Mercurial > cpython-lru_cache-weakref
annotate PC/_subprocess.c @ 38664:7619216bbc19 2.4
Bug #1502728: Correctly link against librt library on HP-UX.
(backport from rev. 46743)
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Thu, 08 Jun 2006 12:54:16 +0000 |
| parents | 913e5e84fade |
| children | 6fb46e87d5f9 |
| rev | line source |
|---|---|
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1 /* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2 * support routines for subprocess module |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3 * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
4 * Currently, this extension module is only required when using the |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
5 * subprocess module on Windows, but in the future, stubs for other |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
6 * platforms might be added here as well. |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
7 * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
8 * Copyright (c) 2004 by Fredrik Lundh <fredrik@pythonware.com> |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
9 * Copyright (c) 2004 by Secret Labs AB, http://www.pythonware.com |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
10 * Copyright (c) 2004 by Peter Astrand <astrand@lysator.liu.se> |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
11 * |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
12 * By obtaining, using, and/or copying this software and/or its |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
13 * associated documentation, you agree that you have read, understood, |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
14 * and will comply with the following terms and conditions: |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
15 * |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
16 * Permission to use, copy, modify, and distribute this software and |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
17 * its associated documentation for any purpose and without fee is |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
18 * hereby granted, provided that the above copyright notice appears in |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
19 * all copies, and that both that copyright notice and this permission |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
20 * notice appear in supporting documentation, and that the name of the |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
21 * authors not be used in advertising or publicity pertaining to |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
22 * distribution of the software without specific, written prior |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
23 * permission. |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
24 * |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
25 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
26 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
27 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
28 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
29 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
30 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
31 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
32 * |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
33 */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
34 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
35 /* TODO: handle unicode command lines? */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
36 /* TODO: handle unicode environment? */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
37 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
38 #include "Python.h" |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
39 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
40 #define WINDOWS_LEAN_AND_MEAN |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
41 #include "windows.h" |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
42 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
43 /* -------------------------------------------------------------------- */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
44 /* handle wrapper. note that this library uses integers when passing |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
45 handles to a function, and handle wrappers when returning handles. |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
46 the wrapper is used to provide Detach and Close methods */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
47 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
48 typedef struct { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
49 PyObject_HEAD |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
50 HANDLE handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
51 } sp_handle_object; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
52 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
53 staticforward PyTypeObject sp_handle_type; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
54 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
55 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
56 sp_handle_new(HANDLE handle) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
57 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
58 sp_handle_object* self; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
59 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
60 self = PyObject_NEW(sp_handle_object, &sp_handle_type); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
61 if (self == NULL) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
62 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
63 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
64 self->handle = handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
65 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
66 return (PyObject*) self; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
67 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
68 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
69 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
70 sp_handle_detach(sp_handle_object* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
71 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
72 HANDLE handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
73 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
74 if (! PyArg_ParseTuple(args, ":Detach")) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
75 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
76 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
77 handle = self->handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
78 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
79 self->handle = NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
80 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
81 /* note: return the current handle, as an integer */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
82 return PyInt_FromLong((long) handle); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
83 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
84 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
85 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
86 sp_handle_close(sp_handle_object* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
87 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
88 if (! PyArg_ParseTuple(args, ":Close")) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
89 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
90 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
91 if (self->handle != INVALID_HANDLE_VALUE) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
92 CloseHandle(self->handle); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
93 self->handle = INVALID_HANDLE_VALUE; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
94 } |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
95 Py_INCREF(Py_None); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
96 return Py_None; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
97 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
98 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
99 static void |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
100 sp_handle_dealloc(sp_handle_object* self) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
101 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
102 if (self->handle != INVALID_HANDLE_VALUE) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
103 CloseHandle(self->handle); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
104 PyMem_DEL(self); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
105 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
106 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
107 static PyMethodDef sp_handle_methods[] = { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
108 {"Detach", (PyCFunction) sp_handle_detach, 1}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
109 {"Close", (PyCFunction) sp_handle_close, 1}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
110 {NULL, NULL} |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
111 }; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
112 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
113 static PyObject* |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
114 sp_handle_getattr(sp_handle_object* self, char* name) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
115 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
116 return Py_FindMethod(sp_handle_methods, (PyObject*) self, name); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
117 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
118 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
119 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
120 sp_handle_as_int(sp_handle_object* self) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
121 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
122 return PyInt_FromLong((long) self->handle); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
123 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
124 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
125 static PyNumberMethods sp_handle_as_number; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
126 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
127 statichere PyTypeObject sp_handle_type = { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
128 PyObject_HEAD_INIT(NULL) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
129 0, /*ob_size*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
130 "_subprocess_handle", sizeof(sp_handle_object), 0, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
131 (destructor) sp_handle_dealloc, /*tp_dealloc*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
132 0, /*tp_print*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
133 (getattrfunc) sp_handle_getattr,/*tp_getattr*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
134 0, /*tp_setattr*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
135 0, /*tp_compare*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
136 0, /*tp_repr*/ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
137 &sp_handle_as_number, /*tp_as_number */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
138 0, /*tp_as_sequence */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
139 0, /*tp_as_mapping */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
140 0 /*tp_hash*/ |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
141 }; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
142 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
143 /* -------------------------------------------------------------------- */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
144 /* windows API functions */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
145 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
146 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
147 sp_GetStdHandle(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
148 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
149 HANDLE handle; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
150 int std_handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
151 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
152 if (! PyArg_ParseTuple(args, "i:GetStdHandle", &std_handle)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
153 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
154 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
155 Py_BEGIN_ALLOW_THREADS |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
156 handle = GetStdHandle((DWORD) std_handle); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
157 Py_END_ALLOW_THREADS |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
158 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
159 if (handle == INVALID_HANDLE_VALUE) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
160 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
161 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
162 if (! handle) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
163 Py_INCREF(Py_None); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
164 return Py_None; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
165 } |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
166 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
167 /* note: returns integer, not handle object */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
168 return PyInt_FromLong((long) handle); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
169 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
170 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
171 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
172 sp_GetCurrentProcess(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
173 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
174 if (! PyArg_ParseTuple(args, ":GetCurrentProcess")) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
175 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
176 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
177 return sp_handle_new(GetCurrentProcess()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
178 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
179 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
180 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
181 sp_DuplicateHandle(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
182 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
183 HANDLE target_handle; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
184 BOOL result; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
185 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
186 long source_process_handle; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
187 long source_handle; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
188 long target_process_handle; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
189 int desired_access; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
190 int inherit_handle; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
191 int options = 0; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
192 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
193 if (! PyArg_ParseTuple(args, "lllii|i:DuplicateHandle", |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
194 &source_process_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
195 &source_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
196 &target_process_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
197 &desired_access, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
198 &inherit_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
199 &options)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
200 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
201 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
202 Py_BEGIN_ALLOW_THREADS |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
203 result = DuplicateHandle( |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
204 (HANDLE) source_process_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
205 (HANDLE) source_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
206 (HANDLE) target_process_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
207 &target_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
208 desired_access, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
209 inherit_handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
210 options |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
211 ); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
212 Py_END_ALLOW_THREADS |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
213 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
214 if (! result) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
215 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
216 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
217 return sp_handle_new(target_handle); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
218 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
219 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
220 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
221 sp_CreatePipe(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
222 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
223 HANDLE read_pipe; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
224 HANDLE write_pipe; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
225 BOOL result; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
226 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
227 PyObject* pipe_attributes; /* ignored */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
228 int size; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
229 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
230 if (! PyArg_ParseTuple(args, "Oi:CreatePipe", &pipe_attributes, &size)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
231 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
232 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
233 Py_BEGIN_ALLOW_THREADS |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
234 result = CreatePipe(&read_pipe, &write_pipe, NULL, size); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
235 Py_END_ALLOW_THREADS |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
236 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
237 if (! result) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
238 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
239 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
240 return Py_BuildValue( |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
241 "NN", sp_handle_new(read_pipe), sp_handle_new(write_pipe)); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
242 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
243 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
244 /* helpers for createprocess */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
245 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
246 static int |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
247 getint(PyObject* obj, char* name) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
248 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
249 PyObject* value; |
|
38590
913e5e84fade
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
33929
diff
changeset
|
250 int ret; |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
251 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
252 value = PyObject_GetAttrString(obj, name); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
253 if (! value) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
254 PyErr_Clear(); /* FIXME: propagate error? */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
255 return 0; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
256 } |
|
38590
913e5e84fade
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
33929
diff
changeset
|
257 ret = (int) PyInt_AsLong(value); |
|
913e5e84fade
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
33929
diff
changeset
|
258 Py_DECREF(value); |
|
913e5e84fade
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
33929
diff
changeset
|
259 return ret; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
260 } |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
261 |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
262 static HANDLE |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
263 gethandle(PyObject* obj, char* name) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
264 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
265 sp_handle_object* value; |
|
38590
913e5e84fade
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
33929
diff
changeset
|
266 HANDLE ret; |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
267 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
268 value = (sp_handle_object*) PyObject_GetAttrString(obj, name); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
269 if (! value) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
270 PyErr_Clear(); /* FIXME: propagate error? */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
271 return NULL; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
272 } |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
273 if (value->ob_type != &sp_handle_type) |
|
38590
913e5e84fade
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
33929
diff
changeset
|
274 ret = NULL; |
|
913e5e84fade
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
33929
diff
changeset
|
275 else |
|
913e5e84fade
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
33929
diff
changeset
|
276 ret = value->handle; |
|
913e5e84fade
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
33929
diff
changeset
|
277 Py_DECREF(value); |
|
913e5e84fade
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
33929
diff
changeset
|
278 return ret; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
279 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
280 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
281 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
282 getenvironment(PyObject* environment) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
283 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
284 int i, envsize; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
285 PyObject* out = NULL; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
286 PyObject* keys; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
287 PyObject* values; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
288 char* p; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
289 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
290 /* convert environment dictionary to windows enviroment string */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
291 if (! PyMapping_Check(environment)) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
292 PyErr_SetString( |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
293 PyExc_TypeError, "environment must be dictionary or None"); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
294 return NULL; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
295 } |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
296 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
297 envsize = PyMapping_Length(environment); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
298 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
299 keys = PyMapping_Keys(environment); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
300 values = PyMapping_Values(environment); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
301 if (!keys || !values) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
302 goto error; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
303 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
304 out = PyString_FromStringAndSize(NULL, 2048); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
305 if (! out) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
306 goto error; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
307 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
308 p = PyString_AS_STRING(out); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
309 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
310 for (i = 0; i < envsize; i++) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
311 int ksize, vsize, totalsize; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
312 PyObject* key = PyList_GET_ITEM(keys, i); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
313 PyObject* value = PyList_GET_ITEM(values, i); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
314 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
315 if (! PyString_Check(key) || ! PyString_Check(value)) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
316 PyErr_SetString(PyExc_TypeError, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
317 "environment can only contain strings"); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
318 goto error; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
319 } |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
320 ksize = PyString_GET_SIZE(key); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
321 vsize = PyString_GET_SIZE(value); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
322 totalsize = (p - PyString_AS_STRING(out)) + ksize + 1 + |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
323 vsize + 1 + 1; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
324 if (totalsize > PyString_GET_SIZE(out)) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
325 int offset = p - PyString_AS_STRING(out); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
326 _PyString_Resize(&out, totalsize + 1024); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
327 p = PyString_AS_STRING(out) + offset; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
328 } |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
329 memcpy(p, PyString_AS_STRING(key), ksize); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
330 p += ksize; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
331 *p++ = '='; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
332 memcpy(p, PyString_AS_STRING(value), vsize); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
333 p += vsize; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
334 *p++ = '\0'; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
335 } |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
336 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
337 /* add trailing null byte */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
338 *p++ = '\0'; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
339 _PyString_Resize(&out, p - PyString_AS_STRING(out)); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
340 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
341 /* PyObject_Print(out, stdout, 0); */ |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
342 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
343 return out; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
344 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
345 error: |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
346 Py_XDECREF(out); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
347 Py_XDECREF(keys); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
348 Py_XDECREF(values); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
349 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
350 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
351 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
352 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
353 sp_CreateProcess(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
354 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
355 BOOL result; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
356 PROCESS_INFORMATION pi; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
357 STARTUPINFO si; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
358 PyObject* environment; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
359 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
360 char* application_name; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
361 char* command_line; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
362 PyObject* process_attributes; /* ignored */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
363 PyObject* thread_attributes; /* ignored */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
364 int inherit_handles; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
365 int creation_flags; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
366 PyObject* env_mapping; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
367 char* current_directory; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
368 PyObject* startup_info; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
369 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
370 if (! PyArg_ParseTuple(args, "zzOOiiOzO:CreateProcess", |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
371 &application_name, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
372 &command_line, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
373 &process_attributes, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
374 &thread_attributes, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
375 &inherit_handles, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
376 &creation_flags, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
377 &env_mapping, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
378 ¤t_directory, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
379 &startup_info)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
380 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
381 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
382 ZeroMemory(&si, sizeof(si)); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
383 si.cb = sizeof(si); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
384 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
385 /* note: we only support a small subset of all SI attributes */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
386 si.dwFlags = getint(startup_info, "dwFlags"); |
|
33929
66223a9ebe48
When using shell=True on Windows, don't display a shell window by default. Fixes #1057061.
Peter Astrand <astrand@lysator.liu.se>
parents:
33729
diff
changeset
|
387 si.wShowWindow = getint(startup_info, "wShowWindow"); |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
388 si.hStdInput = gethandle(startup_info, "hStdInput"); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
389 si.hStdOutput = gethandle(startup_info, "hStdOutput"); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
390 si.hStdError = gethandle(startup_info, "hStdError"); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
391 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
392 if (env_mapping == Py_None) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
393 environment = NULL; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
394 else { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
395 environment = getenvironment(env_mapping); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
396 if (! environment) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
397 return NULL; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
398 } |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
399 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
400 Py_BEGIN_ALLOW_THREADS |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
401 result = CreateProcess(application_name, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
402 command_line, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
403 NULL, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
404 NULL, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
405 inherit_handles, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
406 creation_flags, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
407 environment ? PyString_AS_STRING(environment) : NULL, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
408 current_directory, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
409 &si, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
410 &pi); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
411 Py_END_ALLOW_THREADS |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
412 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
413 Py_XDECREF(environment); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
414 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
415 if (! result) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
416 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
417 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
418 return Py_BuildValue("NNii", |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
419 sp_handle_new(pi.hProcess), |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
420 sp_handle_new(pi.hThread), |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
421 pi.dwProcessId, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
422 pi.dwThreadId); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
423 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
424 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
425 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
426 sp_GetExitCodeProcess(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
427 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
428 DWORD exit_code; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
429 BOOL result; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
430 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
431 long process; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
432 if (! PyArg_ParseTuple(args, "l:GetExitCodeProcess", &process)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
433 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
434 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
435 result = GetExitCodeProcess((HANDLE) process, &exit_code); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
436 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
437 if (! result) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
438 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
439 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
440 return PyInt_FromLong(exit_code); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
441 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
442 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
443 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
444 sp_WaitForSingleObject(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
445 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
446 DWORD result; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
447 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
448 long handle; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
449 int milliseconds; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
450 if (! PyArg_ParseTuple(args, "li:WaitForSingleObject", |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
451 &handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
452 &milliseconds)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
453 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
454 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
455 Py_BEGIN_ALLOW_THREADS |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
456 result = WaitForSingleObject((HANDLE) handle, (DWORD) milliseconds); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
457 Py_END_ALLOW_THREADS |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
458 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
459 if (result == WAIT_FAILED) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
460 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
461 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
462 return PyInt_FromLong((int) result); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
463 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
464 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
465 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
466 sp_GetVersion(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
467 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
468 if (! PyArg_ParseTuple(args, ":GetVersion")) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
469 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
470 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
471 return PyInt_FromLong((int) GetVersion()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
472 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
473 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
474 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
475 sp_GetModuleFileName(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
476 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
477 BOOL result; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
478 long module; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
479 TCHAR filename[MAX_PATH]; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
480 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
481 if (! PyArg_ParseTuple(args, "l:GetModuleFileName", &module)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
482 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
483 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
484 result = GetModuleFileName((HMODULE)module, filename, MAX_PATH); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
485 filename[MAX_PATH-1] = '\0'; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
486 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
487 if (! result) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
488 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
489 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
490 return PyString_FromString(filename); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
491 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
492 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
493 static PyMethodDef sp_functions[] = { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
494 {"GetStdHandle", sp_GetStdHandle, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
495 {"GetCurrentProcess", sp_GetCurrentProcess, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
496 {"DuplicateHandle", sp_DuplicateHandle, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
497 {"CreatePipe", sp_CreatePipe, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
498 {"CreateProcess", sp_CreateProcess, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
499 {"GetExitCodeProcess", sp_GetExitCodeProcess, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
500 {"WaitForSingleObject", sp_WaitForSingleObject, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
501 {"GetVersion", sp_GetVersion, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
502 {"GetModuleFileName", sp_GetModuleFileName, METH_VARARGS}, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
503 {NULL, NULL} |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
504 }; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
505 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
506 /* -------------------------------------------------------------------- */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
507 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
508 static void |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
509 defint(PyObject* d, const char* name, int value) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
510 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
511 PyObject* v = PyInt_FromLong((long) value); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
512 if (v) { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
513 PyDict_SetItemString(d, (char*) name, v); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
514 Py_DECREF(v); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
515 } |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
516 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
517 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
518 #if PY_VERSION_HEX >= 0x02030000 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
519 PyMODINIT_FUNC |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
520 #else |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
521 DL_EXPORT(void) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
522 #endif |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
523 init_subprocess() |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
524 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
525 PyObject *d; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
526 PyObject *m; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
527 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
528 /* patch up object descriptors */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
529 sp_handle_type.ob_type = &PyType_Type; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
530 sp_handle_as_number.nb_int = (unaryfunc) sp_handle_as_int; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
531 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
532 m = Py_InitModule("_subprocess", sp_functions); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
533 d = PyModule_GetDict(m); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
534 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
535 /* constants */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
536 defint(d, "STD_INPUT_HANDLE", STD_INPUT_HANDLE); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
537 defint(d, "STD_OUTPUT_HANDLE", STD_OUTPUT_HANDLE); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
538 defint(d, "STD_ERROR_HANDLE", STD_ERROR_HANDLE); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
539 defint(d, "DUPLICATE_SAME_ACCESS", DUPLICATE_SAME_ACCESS); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
540 defint(d, "STARTF_USESTDHANDLES", STARTF_USESTDHANDLES); |
|
33929
66223a9ebe48
When using shell=True on Windows, don't display a shell window by default. Fixes #1057061.
Peter Astrand <astrand@lysator.liu.se>
parents:
33729
diff
changeset
|
541 defint(d, "STARTF_USESHOWWINDOW", STARTF_USESHOWWINDOW); |
|
66223a9ebe48
When using shell=True on Windows, don't display a shell window by default. Fixes #1057061.
Peter Astrand <astrand@lysator.liu.se>
parents:
33729
diff
changeset
|
542 defint(d, "SW_HIDE", SW_HIDE); |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
543 defint(d, "INFINITE", INFINITE); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
544 defint(d, "WAIT_OBJECT_0", WAIT_OBJECT_0); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
545 defint(d, "CREATE_NEW_CONSOLE", CREATE_NEW_CONSOLE); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
546 } |
