I'm starting a console application, but when I redirect the standard output I always get nothing!
When I don't redirect it, and set CreateNoWindow
to false
, I see everything correctly in the console, but when I redirect it, StandardOutput.ReadToEnd()
always returns an empty string.
Process cproc = new Process();
cproc.StartInfo.CreateNoWindow = true;
cproc.StartInfo.FileName = Dest;
cproc.StartInfo.RedirectStandardOutput = true;
cproc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cproc.StartInfo.UseShellExecute = false;
cproc.EnableRaisingEvents = true;
cproc.Start();
cproc.Exited += new EventHandler(cproc_Exited);
while(!stop)
{
result += cproc.StandardOutput.ReadToEnd();
}
The EventHandler cproc_exited
just sets stop
to true
. Can someone explain why result
is always string.Empty
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…