If you use CreateProcess with the CREATE_NEW_CONSOLE flag, the new process has its own standard input, output, and error commands directed to a new console window. If you want to redefine I / O streams, you can do this by setting the descriptors in the STARTUPINFO hStdOutput, hStdInput and hStdError fields and setting the STARTF_USESTDHANDLES flag.
But what if you want to override only one of the descriptors? For example, I could redirect stderr to a file, leaving stdout and stdin connected to a new console window.
The STARTF_USESTDHANDLES flag tells CreateProcess to replace all descriptors instead of connecting them to new console windows. Looks like we should provide all three pens. Obviously, I can set hStdError to the log file descriptor, but what values should be used for hStdInput and hStdOutput?
I tried using NULL, which seems to work on Windows 8.1, but it does not work on Windows 7.
I also thought about creating a console window first, and then called CreateProcess with the descriptors of the new console window buffers (and lowered the CREATE_NEW_CONSOLE flag). Unfortunately, the parent process is also a console application, and it looks like the console application cannot create a second console window.
source
share