blob: d96d0f5e5876dd0c0070803a739534df06d4cbf3 [file] [log] [blame]
Fredrik Lundh43298d12000-07-09 11:35:36 +00001/*
2 * w9xpopen.c
3 *
4 * Serves as an intermediate stub Win32 console application to
5 * avoid a hanging pipe when redirecting 16-bit console based
6 * programs (including MS-DOS console based programs and batch
7 * files) on Window 95 and Windows 98.
8 *
9 * This program is to be launched with redirected standard
10 * handles. It will launch the command line specified 16-bit
11 * console based application in the same console, forwarding
12 * it's own redirected standard handles to the 16-bit child.
13
14 * AKA solution to the problem described in KB: Q150956.
15 */
16
17#define WINDOWS_LEAN_AND_MEAN
18#include <windows.h>
19
20const char *usage =
21"This program is used by Python's os.pipe function to\n"
22"to work around a limitation in Windows 95/98. It is\n"
23"not designed to be used as stand-alone program.";
24
25int main(int argc, char *argv[])
26{
27 BOOL bRet;
28 STARTUPINFO si;
29 PROCESS_INFORMATION pi;
Mark Hammondfb439ab2000-08-14 05:04:28 +000030 DWORD exit_code=0;
Fredrik Lundh43298d12000-07-09 11:35:36 +000031
32 if (argc != 2) {
33 MessageBox(NULL, usage, argv[0], MB_OK);
34 return 1;
35 }
36
37 /* Make child process use this app's standard files. */
38 ZeroMemory(&si, sizeof si);
39 si.cb = sizeof si;
40 si.dwFlags = STARTF_USESTDHANDLES;
41 si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
42 si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
43 si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
44
45 bRet = CreateProcess(
46 NULL, argv[1],
47 NULL, NULL,
48 TRUE, 0,
49 NULL, NULL,
50 &si, &pi
51 );
52
53 if (bRet) {
Mark Hammondfb439ab2000-08-14 05:04:28 +000054 if (WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_FAILED) {
55 GetExitCodeProcess(pi.hProcess, &exit_code);
56 }
Fredrik Lundh43298d12000-07-09 11:35:36 +000057 CloseHandle(pi.hProcess);
58 CloseHandle(pi.hThread);
Mark Hammondfb439ab2000-08-14 05:04:28 +000059 return exit_code;
Fredrik Lundh43298d12000-07-09 11:35:36 +000060 }
61
62 return 1;
63}