Click to See Complete Forum and Search --> : Not just redirecting stdout ...
Milhouse100
March 4th, 2003, 09:00 AM
Hi,
I know that there are already some topics about redirecting stdout, but I miss one issue:
If you want to redirect a console apps output and process it e.g. in a MFC app you can use a pipe and ReadFile().
Now you have a console app that just prints out a status every second for a few minutes and you want to check within your MFC app if the status has changed.
I have found no code that can handle this. It seems that all pipes are buffered an ReadFile() only returns with valid data if the buffer is full or flushed. So in worst case you have to wait until the console app has ended.
Does anyone know how to handle this issue ?
Thanks
Milhouse
AlionSolutions
March 7th, 2003, 06:36 AM
I answer anyway ;o)
Ok, so what do you want do to. You talk about a console-app and then about a mfc-app. if you are just looking for some scheme for getting some output to a consoles output and also to a gui, why not just call a update-function of your gui to tell the gui, that there is something to show.
ok, just tell me if i'm on the wrong track. if not, and you need some more help, just ask.
if I'm right, you should work a little in the implementation of some model/view/controller-paradigm to get things real smart :cool:
bye for now
Juergen
Milhouse100
March 7th, 2003, 07:06 AM
Now I am not sure what you mean :)
O.k., I have a MFC app. This MFC app creates a new process using CreateProcess(). This new process is a Win32 console app and does some output to stdout. In my case it outputs a status message every second.
Now I want to analyze this output within my MFC app. If the status has changed the console app will print a different status to stdout. So if I have redirected its stdout to my MFC app I can analyze its output and recognize if the status has changed. And if so I would like to show a message window saying that the status has changed.
So I have two processes: First the MFC app and second the console app that was created by the MFC app.
I donīt know anything about the console app. It is not written by myself. I just know that it prints out this status messages.
My idea was to create a pipe in the MFC app, routing stdout to this pipe and to start the console app in a way that it inherits the stdout from the MFC app. When this is done I can read the pipe with ReadFile() in my MFC app and hopefully get the output of the console app.
This works fine but the output of the console app is bufferd (i.e. the pipe is buffered). So ReadFile only returns valid data if this buffer is flushed or if it is full.
This means for me that the console app writes to the pipe. But ReadFile() doesnīt react until the buffer is flushed or full. In my case ReadFile() waits until the console app has ended and then returns with valid data - and that is much too late.
Hope you now have all information you need and thanks for your help !
Milhouse
AlionSolutions
March 8th, 2003, 07:16 AM
sounds to me like imission impossible.
but anyway, this is my level of information.
I don't think that it is possible to just catch the output of your console.
if the output-stream should be catched you have to initiate the "redirection" in the code of the console-app. since this is not your code, I'm affraid tha you can't do this.
If you want to use a pipe or something like that, you have to write the console-output into the pipe. how will you do this ? since you have no access to the source of your console , where do you want to write what to the pipe ?
What you want to do has a little bit of client-server-structure.
you can imagine your console app as something like a server. it has to write the data into some interface that your client (mfc-app) can communicate with.
since there is no doccumented way to simply grab a output-stream from a console, I think this is really mission-impossible.
I read about some API-functions with the word console inside that might help you. I think you'll find them in the MSDN if you search for the term "console",
As I remember, most of those functions were marked as undocumented.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.