blob: 0081af468bf9c992911d6a3692345365fc041da1 [file] [log] [blame]
Guido van Rossum639ccae1998-08-08 20:00:49 +00001/* Minimal main program -- everything is loaded from the library. */
Guido van Rossumd666eae1997-12-10 05:50:18 +00002
Fredrik Lundhddbc1182000-07-08 18:06:41 +00003#define WINDOWS_LEAN_AND_MEAN
Guido van Rossumd666eae1997-12-10 05:50:18 +00004#include <windows.h>
Fredrik Lundhddbc1182000-07-08 18:06:41 +00005#include <fcntl.h>
6#include <sys/stat.h>
7
Guido van Rossum67ab6721998-08-08 19:58:59 +00008#include "Python.h"
Guido van Rossumd666eae1997-12-10 05:50:18 +00009
10extern int Py_Main();
11
12int WINAPI WinMain(
Fredrik Lundhddbc1182000-07-08 18:06:41 +000013 HINSTANCE hInstance, /* handle to current instance */
14 HINSTANCE hPrevInstance, /* handle to previous instance */
15 LPSTR lpCmdLine, /* pointer to command line */
16 int nCmdShow /* show state of window */
Guido van Rossumd666eae1997-12-10 05:50:18 +000017)
18{
Fredrik Lundhddbc1182000-07-08 18:06:41 +000019 int null_file;
20
21 /*
22 * make sure that the C RTL has valid file descriptors for
23 * stdin, stdout, stderr. Use the NUL device if necessary.
24 * This allows popen to work under pythonw.
25 *
26 * When pythonw.exe starts the C RTL function _ioinit is called
27 * first. WinMain is called later hence the need to check for
28 * invalid handles.
29 *
30 * Note: FILE stdin, stdout, stderr do not use the file descriptors
31 * setup here. They are already initialised before WinMain was called.
32 */
33
34 null_file = open("NUL", _O_RDWR);
35
36 if (_get_osfhandle(0) == -1)
37 dup2(null_file, 0);
38
39 if (_get_osfhandle(1) == -1)
40 dup2(null_file, 1);
41
42 if (_get_osfhandle(2) == -1)
43 dup2(null_file, 2);
44
45 close(null_file);
46
47 return Py_Main(__argc, __argv);
Guido van Rossumd666eae1997-12-10 05:50:18 +000048}