[Mono-list] StreamReader
Lee Connell
lee_connell at hotmail.com
Fri Mar 31 20:17:18 EST 2006
I am using System.Diagnostics.Process to execute an external process. When
I set RedirectStandardOutput = true and attempt to read the entire stream
either with ReadToEnd(); or looping with ReadLine(); the application freezes
on the last read.
This happens in linux and windows so I'm assuming it's by design and I'm
doing something wrong.
What do I need to do to read the whole stream and continue with the
application?
String data;
Process proc = new Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
StreamWriter input = proc.StandardInput;
StreamReader output = proc.StandardOutput;
input.AutoFlush = true;
input.Write("dir" + System.Environment.NewLine);
data = output.ReadLine();
while (output.EndOfStream == false)
{
Debug.WriteLine("--- " + data + " ---");
data = output.ReadLine();
<<-------------------------------------------------- when the last read in
the loop occurs the program halts.
}
input.Write("exit" + System.Environment.NewLine);
data = output.ReadLine();
Debug.WriteLine("--- " + data + " ---");
//Debug.WriteLine(data);
input.Close();
output.Close();
proc.Close();
_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee®
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
More information about the Mono-list
mailing list