【发布时间】:2011-06-29 13:56:20
【问题描述】:
我正在调用 ffmpeg。有时调用失败并且ffmpeg不会退出它只会进入递归循环。我已经调用了 WaitForExit 方法。
在代码中,我进一步询问了standardOutput 和standardError。我知道当 ffmpeg 不退出时,它会在控制台屏幕上产生很多垃圾。出于这个原因,我相信当我尝试获取标准输出和标准错误时,c# 代码会崩溃。它仍在被写入。如何判断 c# 是否退出了代码而不是进程自行退出?
我试图查看 process.HasExited 但它不起作用。即使我知道 c# 已经退出进程,它仍然显示为 false。
p.StartInfo.FileName = exePathArg;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.Arguments = argumentsArg;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit(timeToWaitForProcessToExit);
StreamReader standardOutput = p.StandardOutput;
StreamReader standardError = p.StandardError;
retDirects.Add("StandardOutput", standardOutput.ReadToEnd());
retDirects.Add("StandardError", standardError.ReadToEnd());
【问题讨论】:
-
它正在等待您在退出之前读取其输出。你做错了。