Mercurial > cpython-lru_cache-weakref
annotate PC/_subprocess.c @ 39042:c02fa187e0f4 legacy-trunk
Part of SF patch #1484695. This removes dead code. The chksum was
already verified in .frombuf() on the lines above. If there was
a problem an exception is raised, so there was no way this condition
could have been true.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Mon, 10 Jul 2006 00:23:17 +0000 |
| parents | 7d31d031f8e1 |
| children | 1508cea2c6b5 4fe192d48960 |
| 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 |
|
36030
f0a5330f2b3e
added PSF licensing blurbs to relevant files
Fredrik Lundh <fredrik@pythonware.com>
parents:
35856
diff
changeset
|
35 /* Licensed to PSF under a Contributor Agreement. */ |
|
f0a5330f2b3e
added PSF licensing blurbs to relevant files
Fredrik Lundh <fredrik@pythonware.com>
parents:
35856
diff
changeset
|
36 /* See http://www.python.org/2.4/license for licensing details. */ |
|
f0a5330f2b3e
added PSF licensing blurbs to relevant files
Fredrik Lundh <fredrik@pythonware.com>
parents:
35856
diff
changeset
|
37 |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
38 /* TODO: handle unicode command lines? */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
39 /* TODO: handle unicode environment? */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
40 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
41 #include "Python.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 #define WINDOWS_LEAN_AND_MEAN |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
44 #include "windows.h" |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
45 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
46 /* -------------------------------------------------------------------- */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
47 /* 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
|
48 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
|
49 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
|
50 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
51 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
|
52 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
|
53 HANDLE handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
54 } sp_handle_object; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
55 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
56 staticforward PyTypeObject sp_handle_type; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
57 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
58 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
59 sp_handle_new(HANDLE handle) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
60 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
61 sp_handle_object* self; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
62 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
63 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
|
64 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
|
65 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
66 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
67 self->handle = handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
68 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
69 return (PyObject*) self; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
70 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
71 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
72 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
73 sp_handle_detach(sp_handle_object* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
74 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
75 HANDLE handle; |
|
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 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
|
78 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
79 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
80 handle = self->handle; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
81 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
82 self->handle = NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
83 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
84 /* 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
|
85 return PyInt_FromLong((long) handle); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
86 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
87 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
88 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
89 sp_handle_close(sp_handle_object* self, PyObject* args) |
|
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 (! 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
|
92 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
93 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 } |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
98 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
|
99 return Py_None; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
100 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
101 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
102 static void |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
103 sp_handle_dealloc(sp_handle_object* self) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
104 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
105 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
|
106 CloseHandle(self->handle); |
| 37229 | 107 PyObject_FREE(self); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
108 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
109 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
110 static PyMethodDef sp_handle_methods[] = { |
|
38490
a5298f371be7
Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents:
37229
diff
changeset
|
111 {"Detach", (PyCFunction) sp_handle_detach, METH_VARARGS}, |
|
a5298f371be7
Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents:
37229
diff
changeset
|
112 {"Close", (PyCFunction) sp_handle_close, METH_VARARGS}, |
|
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 {NULL, NULL} |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
114 }; |
|
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 static PyObject* |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
117 sp_handle_getattr(sp_handle_object* self, char* name) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
118 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
119 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
|
120 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
121 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
122 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
123 sp_handle_as_int(sp_handle_object* self) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
124 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
125 return PyInt_FromLong((long) self->handle); |
|
33723
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 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
128 static PyNumberMethods sp_handle_as_number; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
129 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
130 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
|
131 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
|
132 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
|
133 "_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
|
134 (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
|
135 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
|
136 (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
|
137 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
|
138 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
|
139 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
|
140 &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
|
141 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
|
142 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
|
143 0 /*tp_hash*/ |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
144 }; |
|
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 /* -------------------------------------------------------------------- */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
147 /* windows API functions */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
148 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
149 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
150 sp_GetStdHandle(PyObject* self, PyObject* args) |
|
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 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
|
153 int std_handle; |
|
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 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
|
156 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
157 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
158 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
|
159 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
|
160 Py_END_ALLOW_THREADS |
|
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 == 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
|
163 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
164 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 } |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
169 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
170 /* 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
|
171 return PyInt_FromLong((long) handle); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
172 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
173 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
174 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
175 sp_GetCurrentProcess(PyObject* self, PyObject* args) |
|
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 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
|
178 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
179 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
180 return sp_handle_new(GetCurrentProcess()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
181 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
182 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
183 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
184 sp_DuplicateHandle(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
185 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
186 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
|
187 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
|
188 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 int options = 0; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
195 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
196 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
|
197 &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
|
198 &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
|
199 &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
|
200 &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
|
201 &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
|
202 &options)) |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
203 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
204 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
205 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
|
206 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
|
207 (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
|
208 (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
|
209 (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
|
210 &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
|
211 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
|
212 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
|
213 options |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
214 ); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
215 Py_END_ALLOW_THREADS |
|
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 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
|
218 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
219 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
220 return sp_handle_new(target_handle); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
221 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
222 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
223 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
224 sp_CreatePipe(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
225 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
226 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
|
227 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
|
228 BOOL result; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
229 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
230 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
|
231 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
|
232 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
233 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
|
234 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
235 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
236 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
|
237 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
|
238 Py_END_ALLOW_THREADS |
|
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 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
|
241 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
242 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
243 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
|
244 "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
|
245 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
246 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
247 /* helpers for createprocess */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
248 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
249 static int |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
250 getint(PyObject* obj, char* name) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
251 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
252 PyObject* value; |
|
38589
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
253 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
|
254 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 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
|
259 } |
|
38589
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
260 ret = (int) PyInt_AsLong(value); |
|
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
261 Py_DECREF(value); |
|
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
262 return ret; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
263 } |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
264 |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
265 static HANDLE |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
266 gethandle(PyObject* obj, char* name) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
267 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
268 sp_handle_object* value; |
|
38589
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
269 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
|
270 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
271 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
|
272 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
|
273 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
|
274 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
|
275 } |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
276 if (value->ob_type != &sp_handle_type) |
|
38589
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
277 ret = NULL; |
|
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
278 else |
|
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
279 ret = value->handle; |
|
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
280 Py_DECREF(value); |
|
7d31d031f8e1
Bug #1500293: fix memory leaks in _subprocess module.
Georg Brandl <georg@python.org>
parents:
38490
diff
changeset
|
281 return ret; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
282 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
283 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
284 static PyObject* |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
285 getenvironment(PyObject* environment) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
286 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
287 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
|
288 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
|
289 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
|
290 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
|
291 char* p; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
292 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
293 /* 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 } |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
299 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
300 envsize = PyMapping_Length(environment); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
301 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 goto error; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
306 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
307 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
|
308 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
|
309 goto error; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
310 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
311 p = PyString_AS_STRING(out); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
312 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
313 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
|
314 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
|
315 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
|
316 PyObject* value = PyList_GET_ITEM(values, i); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
317 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
318 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
|
319 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
|
320 "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
|
321 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
|
322 } |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 _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
|
330 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
|
331 } |
|
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(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
|
333 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
|
334 *p++ = '='; |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
335 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
|
336 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
|
337 *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
|
338 } |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
339 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
340 /* 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
|
341 *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
|
342 _PyString_Resize(&out, p - PyString_AS_STRING(out)); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
343 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
344 /* PyObject_Print(out, stdout, 0); */ |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
345 |
|
35855
429f537cf6d6
r849@spiff: Fredrik | 2005-11-09 10:00:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents:
33929
diff
changeset
|
346 Py_XDECREF(keys); |
|
429f537cf6d6
r849@spiff: Fredrik | 2005-11-09 10:00:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents:
33929
diff
changeset
|
347 Py_XDECREF(values); |
|
429f537cf6d6
r849@spiff: Fredrik | 2005-11-09 10:00:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents:
33929
diff
changeset
|
348 |
|
33729
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 out; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
350 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
351 error: |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
352 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
|
353 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
|
354 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
|
355 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
356 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
357 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
358 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
359 sp_CreateProcess(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
360 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
361 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
|
362 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
|
363 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
|
364 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
|
365 |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
366 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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 PyObject* startup_info; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
375 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
376 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
|
377 &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
|
378 &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
|
379 &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
|
380 &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
|
381 &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
|
382 &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
|
383 &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
|
384 ¤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
|
385 &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
|
386 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
387 |
|
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 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
|
389 si.cb = sizeof(si); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
390 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
391 /* 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
|
392 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
|
393 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
|
394 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
|
395 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
|
396 si.hStdError = gethandle(startup_info, "hStdError"); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
397 |
|
35856
4462871a6dce
r858@spiff: Fredrik | 2005-11-10 23:40:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents:
35855
diff
changeset
|
398 if (PyErr_Occurred()) |
|
4462871a6dce
r858@spiff: Fredrik | 2005-11-10 23:40:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents:
35855
diff
changeset
|
399 return NULL; |
|
4462871a6dce
r858@spiff: Fredrik | 2005-11-10 23:40:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents:
35855
diff
changeset
|
400 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
401 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
|
402 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
|
403 else { |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
404 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
|
405 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
|
406 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
|
407 } |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
408 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
409 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
|
410 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
|
411 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
|
412 NULL, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
413 NULL, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
414 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
|
415 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
|
416 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
|
417 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
|
418 &si, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
419 &pi); |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
420 Py_END_ALLOW_THREADS |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
421 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
422 Py_XDECREF(environment); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
423 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
424 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
|
425 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
426 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
427 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
|
428 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
|
429 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
|
430 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
|
431 pi.dwThreadId); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
432 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
433 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
434 static PyObject * |
|
36086
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
435 sp_TerminateProcess(PyObject* self, PyObject* args) |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
436 { |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
437 BOOL result; |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
438 |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
439 long process; |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
440 int exit_code; |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
441 if (! PyArg_ParseTuple(args, "li:TerminateProcess", &process, |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
442 &exit_code)) |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
443 return NULL; |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
444 |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
445 result = TerminateProcess((HANDLE) process, exit_code); |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
446 |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
447 if (! result) |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
448 return PyErr_SetFromWindowsErr(GetLastError()); |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
449 |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
450 Py_INCREF(Py_None); |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
451 return Py_None; |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
452 } |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
453 |
|
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
454 static PyObject * |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
455 sp_GetExitCodeProcess(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
456 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
457 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
|
458 BOOL result; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
459 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
460 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
|
461 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
|
462 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
463 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
464 result = GetExitCodeProcess((HANDLE) process, &exit_code); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
465 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
466 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
|
467 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
468 |
|
33729
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 PyInt_FromLong(exit_code); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
470 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
471 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
472 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
473 sp_WaitForSingleObject(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
474 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
475 DWORD result; |
|
33723
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 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
|
478 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
|
479 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
|
480 &handle, |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
481 &milliseconds)) |
|
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 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
|
485 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
|
486 Py_END_ALLOW_THREADS |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
487 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
488 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
|
489 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
490 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
491 return PyInt_FromLong((int) result); |
|
33723
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 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
494 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
495 sp_GetVersion(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
496 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
497 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
|
498 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
499 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
500 return PyInt_FromLong((int) GetVersion()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
501 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
502 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
503 static PyObject * |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
504 sp_GetModuleFileName(PyObject* self, PyObject* args) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
505 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
506 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
|
507 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
|
508 TCHAR filename[MAX_PATH]; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
509 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
510 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
|
511 return NULL; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
512 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
513 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
|
514 filename[MAX_PATH-1] = '\0'; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
515 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
516 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
|
517 return PyErr_SetFromWindowsErr(GetLastError()); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
518 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
519 return PyString_FromString(filename); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
520 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
521 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
522 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
|
523 {"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
|
524 {"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
|
525 {"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
|
526 {"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
|
527 {"CreateProcess", sp_CreateProcess, METH_VARARGS}, |
|
36086
e14f47964748
added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents:
36030
diff
changeset
|
528 {"TerminateProcess", sp_TerminateProcess, METH_VARARGS}, |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
529 {"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
|
530 {"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
|
531 {"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
|
532 {"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
|
533 {NULL, NULL} |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
534 }; |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
535 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
536 /* -------------------------------------------------------------------- */ |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
537 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
538 static void |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
539 defint(PyObject* d, const char* name, int value) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
540 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
541 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
|
542 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
|
543 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
|
544 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
|
545 } |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
546 } |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
547 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
548 #if PY_VERSION_HEX >= 0x02030000 |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
549 PyMODINIT_FUNC |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
550 #else |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
551 DL_EXPORT(void) |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
552 #endif |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
553 init_subprocess() |
|
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
554 { |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
555 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
|
556 PyObject *m; |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
557 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
558 /* 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
|
559 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
|
560 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
|
561 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
562 m = Py_InitModule("_subprocess", sp_functions); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36086
diff
changeset
|
563 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36086
diff
changeset
|
564 return; |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
565 d = PyModule_GetDict(m); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
566 |
|
33729
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
567 /* constants */ |
|
0d6d56b2164b
Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents:
33723
diff
changeset
|
568 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
|
569 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
|
570 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
|
571 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
|
572 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
|
573 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
|
574 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
|
575 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
|
576 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
|
577 defint(d, "CREATE_NEW_CONSOLE", CREATE_NEW_CONSOLE); |
|
33723
76641824cf05
Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
578 } |
