Execute a line in a text file
Posted
by
apophis
on Stack Overflow
See other posts from Stack Overflow
or by apophis
Published on 2011-01-15T03:48:15Z
Indexed on
2011/01/15
3:53 UTC
Read the original article
Hit count: 165
Hi
I have a program that reads text files filled with code designed to be executed line by line by the program, like a script file. The problem is that I don't no how to do the line executing part. Here is my code, I thought using the \r would fool the console. But it just shows me a list of lines in the file.
if (tok[0] == "read" && length == 2)
{
try
{
StreamReader tr = new StreamReader(@"C:\Users\Public\"+tok[1]+".txt");
while (!tr.EndOfStream)
{
Console.WriteLine(tr.ReadLine());
}
}
catch
{
Console.WriteLine("No such text file.\n");
}
Prompt();
If I knew what to search for to fix my problem in Google, I would have. But I've got no idea.
Thanks
© Stack Overflow or respective owner