9
是否有重定向衍生進程的標準輸出並捕獲它的發生。在過程完成後,我所看到的所有內容都會執行ReadToEnd。我希望能夠在打印時獲得輸出。C#在運行時獲取進程輸出
編輯:
private void ConvertToMPEG()
{
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
//Setup filename and arguments
p.StartInfo.Arguments = String.Format("-y -i \"{0}\" -target ntsc-dvd -sameq -s 720x480 \"{1}\"", tempDir + "out.avi", tempDir + "out.mpg");
p.StartInfo.FileName = "ffmpeg.exe";
//Handle data received
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
p.Start();
}
void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Debug.WriteLine(e.Data);
}
是的,此外,您需要將'RedirectStandardOutput'設置爲true才能工作。 – vcsjones 2012-08-16 20:05:07
@vcsjones:只需要額外的貼子。 – Tigran 2012-08-16 20:05:25
在答案[在這裏](http://stackoverflow.com/a/3642517/74757)。 – 2012-08-16 20:06:04