diff options
| author | Fredrik Lundh <fredrik@pythonware.com> | 2000-07-08 18:06:41 +0000 |
|---|---|---|
| committer | Fredrik Lundh <fredrik@pythonware.com> | 2000-07-08 18:06:41 +0000 |
| commit | be5b338bed8d08a8e00761936944f1ff42fe25ff (patch) | |
| tree | 6f4d2d215023dc714e59c6c9e014094c673ad6eb /PC | |
| parent | 782fcd4709d32215b0c8b57d51e2c292bf10d340 (diff) | |
| download | cpython-be5b338bed8d08a8e00761936944f1ff42fe25ff.tar.gz | |
- this is a tentative checkin of the #100764 patch (by
Barry Scott). it appears to solve the problem on NT
and 2000, but not on Windows 95.
in other words, it's better than before, but not per-
fect. I'll leave the patch open for now.
Diffstat (limited to 'PC')
| -rw-r--r-- | PC/WinMain.c | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/PC/WinMain.c b/PC/WinMain.c index 36aa90353f..0081af468b 100644 --- a/PC/WinMain.c +++ b/PC/WinMain.c @@ -1,16 +1,48 @@ /* Minimal main program -- everything is loaded from the library. */ +#define WINDOWS_LEAN_AND_MEAN #include <windows.h> +#include <fcntl.h> +#include <sys/stat.h> + #include "Python.h" extern int Py_Main(); int WINAPI WinMain( - HINSTANCE hInstance, // handle to current instance - HINSTANCE hPrevInstance, // handle to previous instance - LPSTR lpCmdLine, // pointer to command line - int nCmdShow // show state of window + HINSTANCE hInstance, /* handle to current instance */ + HINSTANCE hPrevInstance, /* handle to previous instance */ + LPSTR lpCmdLine, /* pointer to command line */ + int nCmdShow /* show state of window */ ) { - return Py_Main(__argc, __argv); + int null_file; + + /* + * make sure that the C RTL has valid file descriptors for + * stdin, stdout, stderr. Use the NUL device if necessary. + * This allows popen to work under pythonw. + * + * When pythonw.exe starts the C RTL function _ioinit is called + * first. WinMain is called later hence the need to check for + * invalid handles. + * + * Note: FILE stdin, stdout, stderr do not use the file descriptors + * setup here. They are already initialised before WinMain was called. + */ + + null_file = open("NUL", _O_RDWR); + + if (_get_osfhandle(0) == -1) + dup2(null_file, 0); + + if (_get_osfhandle(1) == -1) + dup2(null_file, 1); + + if (_get_osfhandle(2) == -1) + dup2(null_file, 2); + + close(null_file); + + return Py_Main(__argc, __argv); } |
