C# 进程。启动标准输出始终为空
我尝试了在这里和其他地方发布的大量示例,它们应该捕获并输出process.start命令的标准输出。但无论是同步还是异步,输出总是空的C# 进程。启动标准输出始终为空,c#,C#,我尝试了在这里和其他地方发布的大量示例,它们应该捕获并输出process.start命令的标准输出。但无论是同步还是异步,输出总是空的 StringBuilder outputBuilder; ProcessStartInfo processStartInfo; Process process; outputBuilder = new StringBuilder(); processStartInfo = new ProcessStartInfo(); processStartInfo.Cr
StringBuilder outputBuilder;
ProcessStartInfo processStartInfo;
Process process;
outputBuilder = new StringBuilder();
processStartInfo = new ProcessStartInfo();
processStartInfo.CreateNoWindow = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.UseShellExecute = false;
processStartInfo.Arguments = "-ss 00:00:50 -t 240 -i Input.MOV -to 00:00:02 -qscale 0 _OUTPUT.MOV";
processStartInfo.FileName = "ffmpeg.exe";
process = new Process();
process.StartInfo = processStartInfo;
// enable raising events because Process does not raise events by default
process.EnableRaisingEvents = true;
// attach the event handler for OutputDataReceived before starting the process
process.OutputDataReceived += new DataReceivedEventHandler
(
delegate(object sender, DataReceivedEventArgs e)
{
// append the new data to the data already read-in
outputBuilder.Append(e.Data);
}
);
// start the process
// then begin asynchronously reading the output
// then wait for the process to exit
// then cancel asynchronously reading the output
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
process.CancelOutputRead();
// use the output
string output = outputBuilder.ToString();
进程按预期执行,但并没有捕获输出,尽管它显示在VSIDE输出窗格中
知道这里出了什么问题吗
致意。谢谢艾米,这是正确的,正常输出由返回
BeginErrorReadLine
还可以使用
BeginErrorReadLine
和等效处理程序侦听错误。delegate(对象发送方,DataReceivedEventArgs e)
这看起来是错误的。只需拆下它以及与之配套的打开/关闭支架。