我的程序一直运行良好,但突然卡在 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);
}