是我的代碼命令重定向問題
//Create process
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
//strCommand is path and file name of command to run
pProcess.StartInfo.FileName = "ffmpeg.exe";
//strCommandParameters are parameters to pass to program
pProcess.StartInfo.Arguments = "-i " + videoName;
pProcess.StartInfo.UseShellExecute = false;
//Set output of program to be written to process output stream
pProcess.StartInfo.RedirectStandardOutput = true;
//Start the process
pProcess.Start();
//Get program output
string strOutput = pProcess.StandardOutput.ReadToEnd();
//Wait for process to finish
pProcess.WaitForExit();
命令的作品,但strOutput
字符串是空的,結果在控制檯中顯示。我在這裏錯過了什麼嗎?
是實際解決。 我也可以做類似 string strOutput = pProcess.StandardOutput.ReadToEnd(); strOutput = pProcess.StandardError.ReadToEnd(); –
你可以,但你會亂序得到消息(例如,所有的standardError將在standardOutput之後)。這可能適合您的目的,但如果您按照正確的順序一起使用它,則必須使用我的帖子中提到的異步。 – Joe