Click here to Skip to main content
15,036,891 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi everybody!

First of all, please excuse me if my English is not perfect, I'm not a native speaker.

Let me first describe what I'm up to:
I want to create a GUI for a command line tool which I have not written by myself.

I got so far to be able to launch the tool with desired parameters and catch its output stream to write it to a text box. I do this in a BackgroundWorker.

But now I got the following problem:
This command line tool controls other command line tools (rtmpdump and ffmpeg among others) to process certain data. If I open the tool manually in the Windows shell I can see the output of the tool itself, directly followerd by the output of the external tools...

In my wannabe GUI app, the output breaks as soon as the output of the actual command line tool ends and the output of the tools triggerd by it should be visible. Based on the files that are created, I can see that the external tools continue to run in the background nevertheless, but the BackgroundWorker finishes and I can not go on analysing the output stream.

This is what I use for reading out the stream:
while (! process.StandardOutput.EndOfStream)

So EndOfStream is reached as soon as the commandline tool runs the other tools, or in a nutshell: I can only read the output stream of the initial process, but not of those triggered by it.

I can't believe this should not be possible with C#... I think there MUST be a way to capture the console just like I was opening the tool manually in the cmd.

Up to this important detail, that stops me from proceeding with the whole GUI project, I have been able to acquire any information from docs or via Google. But now I'm realy stuck. Does anyone have an idea?

Thank you in advance!

Kind regards

PS: Even setting StartInfo.WorkingDirectory of the current working directory did not have the desired effect.
Updated 2-Feb-11 21:48pm
Sunasara Imdadhusen 3-Feb-11 3:48am
Added code formatting!
C. Groß 3-Feb-11 3:51am
Oh, sorry I forgot to add the right attribute!

1 solution

I'm thinking of a solution, but it's not elegant and I'm even not sure if it will work.

You may try to use ManagementEventWatcher to get notified of process creation, then get the process you are interested in to redirect its standard output... yes, not very elegant as I said :(

For example, this link tells how to do this:[^]

And event if it works, you will probably be notified asynchronously, that is: the process will probably start before you get notified and start to run immediately before you get a chance to redirect its standard ouput (you will then miss the first outputed lines...)
C. Groß 3-Feb-11 5:41am
Thank you, I will give this a try! Missing the first lines should not be a problem at all, as the processes run long enough to get useful data!
C. Groß 3-Feb-11 12:25pm
Sadly, I couldn't get it to work that way... :(
Any further ideas appreciated!
C. Groß 3-Feb-11 13:29pm
Ok, I have been able to progress a bit on that matter, but I do not want to add it as a real "solution" just yet...
If I run the console with 2>&1 at the end (that is: redirecting the StandardError to the StandardOutput), I can see all the rest and I'm able to work with the output.

However, this is more a workaround than a real solution, I will proceed looking closer into this issue and comment as soon as I find out more!
Olivier Levrey 3-Feb-11 13:43pm
I agree. I wouldn't call that "a solution". Hope you will solve this because it might be usefull for others.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900