Click to See Complete Forum and Search --> : console stdout captured only at prog end


Amrouch
April 16th, 2003, 03:53 PM
I am trying to make a gui application that hides a console application that uses menu. In order to do that, I want to capture stdout and replace it by a pipe and replace stin by a pipe. I tried the following sollution :

Using CreateProcess with

StartupInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
StartupInfo.hStdOutput = StdOutWrite;

The problem with this solution is that I get all of the output only at the ending of the console application (I can't get the output byte by byte as it is sent to the screen).

An other thing to say is that the console app, I didn't write it bye my self (I can't change it)

Does someone know why ?

cup
April 17th, 2003, 01:38 AM
It is possible that the buffer is very big and doesn't get flushed until it is full. It doesn't get full so it is only flushed at the end of the program.

Pity you can't change it. Adding a fflush(stdout) after each printf will get it to do what you want.

Amrouch
April 17th, 2003, 01:22 PM
The problem is that the program that writes to the stdout isn't mine and I haven't access at his source code to add a fflush after each printf....

muthuis
April 18th, 2003, 03:49 AM
Can you post your code for create process(not the console app!)? We can probably try it out!

Amrouch
April 18th, 2003, 12:36 PM
The header file is attached here.

Amrouch
April 18th, 2003, 12:38 PM
And the .cpp is here.
You just have to make an instance of the class ad after that call the two methods SetCommandline and Run

eg :
Console->SetCommandLine("c:\\windows\\system32\\cmd.exe");
Console->Run();

Amrouch
April 18th, 2003, 12:44 PM
You have also to override the OnReceiveStdErr and OnReceiveStdOut in a child class.