Thread: Capturing stdout from a child process

  1. #1
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459

    Capturing stdout from a child process

    ** SOLVED **

    Hello All,

    I'm trying to capture stdout from a child process, which I spawn. I create the pipes (to pipe stdout over), then call CreateProcess() with stdout inherited (into the parent process).
    However that's not my problem, it seems that when I call ReadFile() on my stdout handle (of the process) it's blocking, so I get output, but it hangs waiting for more. Even after the child process has ended.

    So my question is, how do I avoid 'hanging' even after the child process has ended? Anyway I could detect if it's still running?

    Sorry if I haven't explained this very well, something like:

    Code:
        DWORD dwRead;
        char buf[256];
    
        while(ReadFile(hChildStdoutRdDup, buf, sizeof(buf), &dwRead, NULL) != FALSE && dwRead > 0)
        {
            buf[dwRead] = '\0';
            MessageBox(NULL, buf, "title", 0);
        }
        /* the loop never breaks, even after the child process has ended */
    Should I make 'hChildStdoutRdDup' non-blocking?

    Full Source is here: http://pastebin.com/m130401a6 troubled area is highlighted

    Thanks in advance!

    EDIT: I'm such a moron, I didn't close the write end of the pipe while I was reading it, so in other words, it was going round in a big circle
    ** SOVLED **
    Last edited by zacs7; 08-07-2007 at 03:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. create a child process that creates a child process
    By cus in forum Linux Programming
    Replies: 9
    Last Post: 01-13-2009, 02:14 PM
  2. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  3. Replies: 2
    Last Post: 07-12-2008, 12:00 PM
  4. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  5. Redirecting STDOUT to STDIN of a child process
    By 0xception in forum Linux Programming
    Replies: 4
    Last Post: 09-13-2005, 11:58 PM