Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Shell GUI
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
Constantin
 
PS: Even setting StartInfo.WorkingDirectory of the current working directory did not have the desired effect.
Posted 2-Feb-11 22:31pm
Edited 2-Feb-11 22:48pm
v2
Comments
Sunasara Imdadhusen at 3-Feb-11 3:48am
   
Added code formatting!
C. Groß at 3-Feb-11 3:51am
   
Oh, sorry I forgot to add the right attribute!

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 Frown | :(
 
For example, this link tells how to do this:
http://codelog.blogial.com/2009/06/25/managementeventwatcher-in-c/[^]
 
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...)
  Permalink  
Comments
C. Groß at 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ß at 3-Feb-11 12:25pm
   
Sadly, I couldn't get it to work that way... :(
Any further ideas appreciated!
C. Groß at 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 at 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)

  Print Answers RSS
0 OriginalGriff 436
1 Maciej Los 249
2 BillWoodruff 199
3 /\jmot 180
4 Suraj Sahoo | Coding Passion 170
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 3 Feb 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100