【发布时间】:2013-07-16 10:46:55
【问题描述】:
我的程序一直运行良好,但突然卡在 Process.WaitForExit();不继续执行下一个命令。我已经多次运行该程序而没有错误。有谁知道我该如何调试这个,或者有谁知道背后的问题是什么?我的 python.exe 可能有问题吗?谢谢!
public static void Process(string location)
{
int ExitCode;
ProcessStartInfo ProcessInfo;
Process Process;
ProcessInfo = new ProcessStartInfo();
ProcessInfo.FileName = location;
ProcessInfo.Arguments = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
"\\parse.py " + Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\cache.cell";
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = false;
ProcessInfo.RedirectStandardOutput = true;
ProcessInfo.RedirectStandardError = true;
Process = Process.Start(ProcessInfo);
// (...)
Process.WaitForExit();
string stderr = Process.StandardError.ReadToEnd();
string stdout = Process.StandardOutput.ReadToEnd();
//Console.WriteLine("STDERR: " + stderr);
//Console.WriteLine("STDOUT: " + stdout);
using (System.IO.StreamWriter file = new System.IO.StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\test.txt"))
{
file.WriteLine(stdout);
}
【问题讨论】:
-
您的程序是否产生大量输出?如果是这样,它可能会被阻止,等待您读取它才能完成。
-
嗨@JonSkeet,程序将生成test.txt。它以前可以运行,但现在似乎有问题。
-
你考虑过挂钩退出事件进行诊断吗?