CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2001
    Location
    Tunis,Tunisia
    Posts
    19

    console stdout captured only at prog end

    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 ?

  2. #2
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    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.
    Succinct is verbose for terse

  3. #3
    Join Date
    Aug 2001
    Location
    Tunis,Tunisia
    Posts
    19
    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....

  4. #4
    Join Date
    Jan 2002
    Location
    TamilNadu, India
    Posts
    158
    Can you post your code for create process(not the console app!)? We can probably try it out!
    Muthu

  5. #5
    Join Date
    Aug 2001
    Location
    Tunis,Tunisia
    Posts
    19
    The header file is attached here.
    Attached Files Attached Files

  6. #6
    Join Date
    Aug 2001
    Location
    Tunis,Tunisia
    Posts
    19
    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();
    Attached Files Attached Files

  7. #7
    Join Date
    Aug 2001
    Location
    Tunis,Tunisia
    Posts
    19
    You have also to override the OnReceiveStdErr and OnReceiveStdOut in a child class.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured