How to capture command line text that is not sent to stdout?

I am using the LAME mp3 command line encoder in a project. I want to see which version someone is using. if I just run LAME.exe without any parameters, I get, for example:

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

if I try to redirect the output to a text file using> to a text file, the text file is empty. Where does this text come from when starting using System.Process in C #?

+6
c # windows cmd lame
source share
4 answers

He probably uses stderr. cmd.exe does not allow stderr to be redirected, and the only way I have ever redirected it is with the djgpp tool.

0
source share

It can be displayed in stderr instead of stdout. You can redirect stderr by doing:

 LAME.exe 2> textfile.txt 

If this shows you information, LAME prints to the standard error stream. If you write a wrapper in C #, you can redirect the standard error and get the threads out of ProcessStartInfo .

+3
source share
  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); 

worked. thanks everyone!

+1
source share

It can be sent to stderr, have you tried this?

Check Process.StandardError .

Try using

 C:\LAME>LAME.exe 2> test.txt 
0
source share

All Articles