PSS ID Number: 150956
Article Last Modified on 5/12/2003
190351 HOWTO: Spawn Console Processes with Redirected Standard Handles
190351 HOWTO: Spawn Console Processes with Redirected Standard Handles
Startupinfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;<BR/> Startupinfo.wShowWindow = SW_HIDE;NOTE: If the original parent application is a Win32 Console application, and the 16-console based application being launched uses the parent's console, then this work around is not needed.
/*++
Module Name:
CONSPAWN.C
Description:
Serves as an intermediate stub Win32 console application to
avoid a hanging pipe when redirecting 16-bit console based
programs (including MS-DOS console based programs and batch
files) on Window 95, Windows 98, and Windows Me.
This program is to be launched with redirected standard
handles. It will launch the command line specified 16-bit
console based application in the same console, forwarding
it's own redirected standard handles to the 16-bit child.
--*/
#include <windows.h>
void main (int argc, char *argv[])
{
BOOL bRet = FALSE;
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
// Make child process use this app's standard files.
si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdInput = GetStdHandle (STD_INPUT_HANDLE);
si.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE);
si.hStdError = GetStdHandle (STD_ERROR_HANDLE);
bRet = CreateProcess (NULL, argv[1],
NULL, NULL,
TRUE, 0,
NULL, NULL,
&si, &pi
);
if (bRet)
{
WaitForSingleObject (pi.hProcess, INFINITE);
CloseHandle (pi.hProcess);
CloseHandle (pi.hThread);
}
}
190351 HOWTO: Spawn Console Processes with Redirected Standard Handles
Additional query words: win95 winnt inherit std redirect
Keywords: kbConsole kbinfo kbKernBase KB150956
Technology: kbAudDeveloper kbOSWin2000 kbOSWin95 kbOSWin98 kbOSWinME kbOSWinNTSearch kbOSWinSearch kbOSWinXP kbOSWinXPSearch kbWin32API kbWin32sSearch