2010-02-05 79 views
6

我在項目中使用LAME命令行mp3編碼器。我希望能夠看到某人正在使用的版本。如果我只是沒有PARAMATERS我得到的,例如執行LAME.exe:如何捕獲未發送到標準輸出的命令行文本?

C:\LAME>LAME.exe 
LAME 32-bits version 3.98.2 (http://www.mp3dev.org/) 

usage: blah blah 
blah blah 

C:\LAME> 

如果我嘗試將輸出重定向到使用文本文件>到一個文本文件中的文本文件是空的。在c#中使用System.Process運行它時,可以從哪裏獲得此文本?

回答

0

它可能使用標準錯誤。 cmd.exe不允許你重定向stderr,並且我重定向它的唯一方法是使用djgpp工具。

+0

我可以看到,在C#使用System.Process?我現在要看看這個謝謝。 – Dave 2010-02-05 17:08:05

+0

嗯,也許我錯了,這個http://support.microsoft.com/kb/110930說,你現在可以重定向stderr。 – 2010-02-05 17:10:22

+0

這總是可以使用cmd – 2010-02-05 17:13:24

3

它可能會輸出到stderr而不是stdout。您可以redirect stderr做:

LAME.exe 2> textfile.txt 

如果這裏顯示的信息,然後LAME是輸出到標準錯誤流。如果您使用C#編寫包裝器,則可以重定向standard error並輸出來自ProcessStartInfo的流。

1
 System.Diagnostics.Process proc = new System.Diagnostics.Process(); 
     proc.EnableRaisingEvents = false; 
     proc.StartInfo.FileName = @"C:\LAME\LAME.exe"; 
     proc.StartInfo.RedirectStandardError = true; 
     proc.StartInfo.UseShellExecute = false; 

     proc.Start(); 
     string output = proc.StandardError.ReadToEnd(); 


     proc.WaitForExit(); 

     MessageBox.Show(output); 

工作。謝謝大家!

相關問題