我正在使用下面的代码来通知执行启动进程的批处理文件是否有任何问题。此消息框显示批处理文件的内容,并未显示导致的问题。如何才能找到批处理文件执行失败的原因?
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(filename);
psi.RedirectStandardOutput = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
System.Diagnostics.Process listFiles;
listFiles = System.Diagnostics.Process.Start(psi);
System.IO.StreamReader myOutput = listFiles.StandardOutput;
listFiles.WaitForExit(2000);
if (listFiles.HasExited)
{
string output = myOutput.ReadToEnd();
MessageBox.Show(output);
}
答案 0 :(得分:3)
尝试阅读listFiles.StandardError
而不是StandardOutput
的内容。