我寫了一個GUI包裝器,它將使用Process類執行openRTSP。我遇到的問題是將輸出重定向到mpeg4視頻文件。我通過在命令行上運行openRTSP來驗證我傳遞的參數是否正確。C#進程類重定向輸出到視頻文件
openRTSP.exe - 一些α參數 - 適用 - 視頻-4 RTSP://video.from.server> video.mp4
的 「> video.mp4」 是我無法複製的東西。
我看過其他使用Process類的例子,但它們似乎只能用ASCII文本工作。
編輯--- 下面是一些更詳細
this.outputStream = new StreamWriter(fileNameToUse, false, Encoding.Default);
try
{
byte[] buffer;
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = new Process())
{
// Assign start info to the process
exeProcess.StartInfo = startInfo;
// Set up the event handler to call back with each line of output
exeProcess.OutputDataReceived += new DataReceivedEventHandler(OnDataReceived);
// Start the Process
exeProcess.Start();
exeProcess.BeginOutputReadLine();
exeProcess.WaitForExit();
}
}
catch (Exception ex) { PrintException(ex); }
finally
{
this.outputStream.Flush();
this.outputStream.Close();
}
// Called asynchronously with a line of data
private void OnDataReceived(object Sender, DataReceivedEventArgs e)
{
lock (this)
{
if (!string.IsNullOrEmpty(e.Data) && (this.outputStream != null))
this.outputStream.WriteLine(e.Data);
}
}
使用的WriteLine寫入的數據接收,當我的應用程序退出的文件大小是一樣的,當我在命令行中運行openRTSP作爲產生「正確的」輸出,即可以播放的mpeg4視頻。當從命令行運行時,openRTSP正在輸出一個mpeg4文件,我將其重定向到mpeg4。
我試着將「> fileNameToUse」添加到分配給startInfo.Arguments的字符串的末尾,但這使得openRTSP立即失敗。
謝謝, 馬特
您可能會發現[MedallionShell](https://github.com/madelson/MedallionShell)庫有趣。它使流程流的重定向非常簡單。 – ChaseMedallion 2014-08-24 18:10:49