How do I capture command-line text that is not sent to stdout?
Asked Answered
S

4

6

I am using the LAME command line mp3 encoder in a project. I want to be able to see what version someone is using. if I just execute LAME.exe with no paramaters 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 redirecting the output to a text file using > to a text file the text file is empty. Where is this text accessable from when running it using System.Process in c#?

Slowmoving answered 5/2, 2010 at 17:5 Comment(0)
Y
0

It's probably using stderr. cmd.exe doesn't allow you to redirect stderr, and the only way I've ever redirected it is with a djgpp tool.

Yonder answered 5/2, 2010 at 17:7 Comment(3)
can i see that in c# using System.Process? I'll look into this now thanks.Slowmoving
Well maybe I'm wrong, this support.microsoft.com/kb/110930 says that you can redirect stderr now.Yonder
that's always been possible using cmdSubstantialize
S
3

It may be output to stderr instead of stdout. You can redirect stderr by doing:

LAME.exe 2> textfile.txt

If this shows you information, then LAME is outputting to the standard error stream. If you write a wrapper in C#, you can redirect the standard error and output streams from ProcessStartInfo.

Substantialize answered 5/2, 2010 at 17:12 Comment(0)
S
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);

worked. thanks all!

Slowmoving answered 5/2, 2010 at 17:16 Comment(0)
S
0

It might be sent to stderr, have you tried that?

Check out Process.StandardError.

Try it out using

C:\LAME>LAME.exe 2> test.txt
Salvia answered 5/2, 2010 at 17:7 Comment(0)
Y
0

It's probably using stderr. cmd.exe doesn't allow you to redirect stderr, and the only way I've ever redirected it is with a djgpp tool.

Yonder answered 5/2, 2010 at 17:7 Comment(3)
can i see that in c# using System.Process? I'll look into this now thanks.Slowmoving
Well maybe I'm wrong, this support.microsoft.com/kb/110930 says that you can redirect stderr now.Yonder
that's always been possible using cmdSubstantialize

© 2022 - 2024 — McMap. All rights reserved.