How to Spawn a Console App and Redirect Standard HandlesLast reviewed: August 5, 1996 |
The information in this article applies to: Microsoft Win32 Application Programming Interface (API) included with: - Microsoft Windows NT versions 3.5 and 3.51 - Microsoft Windows 95 version 4.0 This article discusses spawning a console application with CreateProcess() and redirecting its output. The standard handles are controlled with the STARTUPINFO fields hStdInput, hStdOutput, and hStdError. In Windows NT version 3.1, if a windowed application spawned a console application, you could:
For example, if you redirected hStdInput and hStdOutput, but left hStdError as 0 or INVALID_HANDLE_VALUE, the console application would fail if it tried to write to stderr. This is not a problem for a console application spawning another console application. In Windows NT version 3.5 and later and in Windows 95, if you set any of these fields to INVALID_HANDLE_VALUE, Windows NT will assign the default value to that handle in the console application, rather than leaving it an invalid value. Therefore, if you set STARTF_USESTDHANDLES, but fail to set one of the handle fields, this will not cause a problem for the console application. You can now redirect standard input, but not standard output, and so forth. |
Additional reference words: 3.50 4.00 Last reviewed: August 5, 1996 |