Microsoft KB Archive/105303

FIX: Redirecting Output to an MS-DOS Application PSS ID Number: Q105303 Article last modified on 07-27-1994

3.10

WINDOWS NT

= SYMPTOMS =

The following method is used to redirect output to a child process when it is started from a GUI application:

  Declare STARTUPINFO si.  Set the hStdIn, hStdOut, and/or hStdErr field as desired. Set the dwFlags field to STARTF_USESTDHANDLES.   In CreateProcess, set inherit handles to TRUE. 

NOTE: This method does not work when starting MS-DOS applications.

= RESOLUTION =

As a workaround, use AllocConsole, then the following method:

  Use SetStdHandle to set the desired handles to be inherited. -or- Use DuplicateHandle to change the inheritance property of handles that should not be inherited.   In CreateProcess, set inherit handles to TRUE. </li></ol>

This method creates a blank console window; however, this is necessary because the method doesn’t work otherwise.

= STATUS =

Microsoft has confirmed this to be a bug in Windows NT 3.1. This problem was corrected in Windows NT 3.5.

= MORE INFORMATION =

Note that if you are opening a handle that will be inherited by the child, set SECURITY_ATTRIBUTES.bInheritHandle = TRUE in the call to CreateFile, CreatePipe, and so forth.

For an example of both methods of redirection, see the INHERIT SDK sample.

Additional reference words: 3.10 KBCategory: Prg KBSubcategory: BseProcThrd

=
================================================================

Copyright Microsoft Corporation 1994.