Search code examples
c++winapi

Getting the output from a process created by CreateProcess


In my console app I've created a process by using CreateProcess method. Now, this process either writes to the console "OK" or "Not OK". How can I intercept that information so I can as well as to console write it to a file?


Solution

    • Use CreatePipe to create an anonymous pipe.
    • Set the standard output of your child to be the write end of the pipe
    • Parent process reads from the read end of the pipe
    • Parent process can write to file and console, and wherever.

    See Creating a Child Process with Redirected Input and Output on MSDN for full details.