I'm trying to spawn cmd.exe and write its output to a file. Here's the code:
Code:
m_File=File.CreateText("output.txt");
proc=new Process();
proc.StartInfo.FileName="cmd.exe";
proc.StartInfo.UseShellExecute=false;
proc.StartInfo.RedirectStandardOutput=true;
proc.Start();
m_Out=proc.StandardOutput;
Thread thd=new Thread(new ThreadStart(ReadStdOut));
proc.WaitForExit();
.
.
.
public void ReadStdOut()
{
for (;;)
{
string Output=m_Out.ReadLine();
if (null==Output)
break;
m_File.WriteLine(Output);
}
proc.WaitForExit();
}
I can see an empty console flash quickly on the screen, but the process seems to end straight away, and nothing is written to the file. Shouldn't it write the prompt to the file, and then wait for something from STDIN?
If there is an easier way to do this I would love to know.