Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 43298d1

Browse files
author
Fredrik Lundh
committed
- win95/98 helper for new os.popen code
this should be built as a console application (link with USER32.LIB), and installed in the same directory as the Python DLL.
1 parent c2e7da9 commit 43298d1

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

PC/w9xpopen.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
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+
20+
const 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+
25+
int main(int argc, char *argv[])
26+
{
27+
BOOL bRet;
28+
STARTUPINFO si;
29+
PROCESS_INFORMATION pi;
30+
31+
if (argc != 2) {
32+
MessageBox(NULL, usage, argv[0], MB_OK);
33+
return 1;
34+
}
35+
36+
/* Make child process use this app's standard files. */
37+
ZeroMemory(&si, sizeof si);
38+
si.cb = sizeof si;
39+
si.dwFlags = STARTF_USESTDHANDLES;
40+
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
41+
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
42+
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
43+
44+
bRet = CreateProcess(
45+
NULL, argv[1],
46+
NULL, NULL,
47+
TRUE, 0,
48+
NULL, NULL,
49+
&si, &pi
50+
);
51+
52+
if (bRet) {
53+
WaitForSingleObject(pi.hProcess, INFINITE);
54+
CloseHandle(pi.hProcess);
55+
CloseHandle(pi.hThread);
56+
return 0;
57+
}
58+
59+
return 1;
60+
}

0 commit comments

Comments
 (0)