summaryrefslogtreecommitdiffstats
path: root/PC/w9xpopen.c
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2000-07-09 11:35:36 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2000-07-09 11:35:36 (GMT)
commit43298d1fff01a8cc170722738263b8af7e1119a1 (patch)
tree951525c08817531cc925b9bfac6ed04ce182077c /PC/w9xpopen.c
parentc2e7da9859c54b91b0cb8e20e91be60437a765f6 (diff)
downloadcpython-43298d1fff01a8cc170722738263b8af7e1119a1.zip
cpython-43298d1fff01a8cc170722738263b8af7e1119a1.tar.gz
cpython-43298d1fff01a8cc170722738263b8af7e1119a1.tar.bz2
- 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.
Diffstat (limited to 'PC/w9xpopen.c')
-rw-r--r--PC/w9xpopen.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/PC/w9xpopen.c b/PC/w9xpopen.c
new file mode 100644
index 0000000..160238c
--- /dev/null
+++ b/PC/w9xpopen.c
@@ -0,0 +1,60 @@
+/*
+ * w9xpopen.c
+ *
+ * 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 and Windows 98.
+ *
+ * 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.
+
+ * AKA solution to the problem described in KB: Q150956.
+ */
+
+#define WINDOWS_LEAN_AND_MEAN
+#include <windows.h>
+
+const char *usage =
+"This program is used by Python's os.pipe function to\n"
+"to work around a limitation in Windows 95/98. It is\n"
+"not designed to be used as stand-alone program.";
+
+int main(int argc, char *argv[])
+{
+ BOOL bRet;
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+
+ if (argc != 2) {
+ MessageBox(NULL, usage, argv[0], MB_OK);
+ return 1;
+ }
+
+ /* Make child process use this app's standard files. */
+ ZeroMemory(&si, sizeof si);
+ 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);
+ return 0;
+ }
+
+ return 1;
+}