我正在启动一个控制台应用程序,但是当我重定向标准输出时,我总是得不到任何东西!
当我不重定向它并设置CreateNoWindow为时false,我在控制台中看到了所有内容,但是当我重定向它时,StandardOutput.ReadToEnd()总是返回一个空字符串.
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();
}
Run Code Online (Sandbox Code Playgroud)
在EventHandler cproc_exited刚刚设置stop到true.有人能解释为什么result总是这样string.Empty吗?