annotate PC/_subprocess.c @ 37850:ebe59cd18273

Use explicit relative import for an, ehm, relative import.
author Thomas Wouters <thomas@python.org>
date Tue, 18 Apr 2006 21:41:36 +0000
parents 91dd4d44d3bc
children f731859e9b3b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
37144
91dd4d44d3bc Finish getting rid of statichere/staticforward
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
56 static PyTypeObject sp_handle_type;
33723
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);
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
107 PyMem_DEL(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[] = {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
111 {"Detach", (PyCFunction) sp_handle_detach, 1},
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
112 {"Close", (PyCFunction) sp_handle_close, 1},
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
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
37144
91dd4d44d3bc Finish getting rid of statichere/staticforward
Neal Norwitz <nnorwitz@gmail.com>
parents: 36324
diff changeset
130 static 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;
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
253
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
254 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
255 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
256 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
257 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
258 }
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
259 return (int) PyInt_AsLong(value);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
260 }
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
261
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
262 static HANDLE
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
263 gethandle(PyObject* obj, char* name)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
264 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
265 sp_handle_object* value;
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
266
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
267 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
268 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
269 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
270 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
271 }
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->ob_type != &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
273 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
274 return value->handle;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
275 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
276
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
277 static PyObject*
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
278 getenvironment(PyObject* environment)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
279 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
280 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
281 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
282 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
283 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
284 char* p;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
285
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
286 /* 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
287 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
288 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
289 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
290 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
291 }
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
292
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
293 envsize = PyMapping_Length(environment);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
294
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
295 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
296 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
297 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
298 goto error;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
299
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
300 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
301 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
302 goto error;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
303
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
304 p = PyString_AS_STRING(out);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
305
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
306 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
307 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
308 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
309 PyObject* value = PyList_GET_ITEM(values, i);
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 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
312 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
313 "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
314 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
315 }
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
316 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
317 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
318 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
319 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
320 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
321 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
322 _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
323 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
324 }
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
325 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
326 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
327 *p++ = '=';
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
328 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
329 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
330 *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
331 }
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
332
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
333 /* 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
334 *p++ = '\0';
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
335 _PyString_Resize(&out, p - PyString_AS_STRING(out));
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
336
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
337 /* PyObject_Print(out, stdout, 0); */
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
338
35855
429f537cf6d6 r849@spiff: Fredrik | 2005-11-09 10:00:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents: 33929
diff changeset
339 Py_XDECREF(keys);
429f537cf6d6 r849@spiff: Fredrik | 2005-11-09 10:00:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents: 33929
diff changeset
340 Py_XDECREF(values);
429f537cf6d6 r849@spiff: Fredrik | 2005-11-09 10:00:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents: 33929
diff changeset
341
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
342 return 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 error:
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
345 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
346 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
347 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
348 return NULL;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
349 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
350
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
351 static PyObject *
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
352 sp_CreateProcess(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
353 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
354 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
355 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
356 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
357 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
358
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
359 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
360 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
361 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
362 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
363 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
364 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
365 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
366 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
367 PyObject* startup_info;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
368
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
369 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
370 &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
371 &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
372 &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
373 &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
374 &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
375 &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
376 &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
377 &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
378 &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
379 return NULL;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
380
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
381 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
382 si.cb = sizeof(si);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
383
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
384 /* 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
385 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
386 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
387 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
388 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
389 si.hStdError = gethandle(startup_info, "hStdError");
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
390
35856
4462871a6dce r858@spiff: Fredrik | 2005-11-10 23:40:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents: 35855
diff changeset
391 if (PyErr_Occurred())
4462871a6dce r858@spiff: Fredrik | 2005-11-10 23:40:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents: 35855
diff changeset
392 return NULL;
4462871a6dce r858@spiff: Fredrik | 2005-11-10 23:40:04 +0100
Fredrik Lundh <fredrik@pythonware.com>
parents: 35855
diff changeset
393
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 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
395 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
396 else {
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
397 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
398 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
399 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
400 }
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
401
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
402 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
403 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
404 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
405 NULL,
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
406 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 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
408 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
409 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
410 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
411 &si,
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
412 &pi);
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
413 Py_END_ALLOW_THREADS
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
414
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
415 Py_XDECREF(environment);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
416
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
417 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
418 return PyErr_SetFromWindowsErr(GetLastError());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
419
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
420 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
421 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
422 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
423 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
424 pi.dwThreadId);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
425 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
426
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
427 static PyObject *
36086
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
428 sp_TerminateProcess(PyObject* self, PyObject* args)
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
429 {
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
430 BOOL result;
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
431
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
432 long process;
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
433 int exit_code;
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
434 if (! PyArg_ParseTuple(args, "li:TerminateProcess", &process,
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
435 &exit_code))
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
436 return NULL;
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
437
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
438 result = TerminateProcess((HANDLE) process, exit_code);
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
439
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
440 if (! result)
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
441 return PyErr_SetFromWindowsErr(GetLastError());
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
442
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
443 Py_INCREF(Py_None);
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
444 return Py_None;
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
445 }
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 static PyObject *
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
448 sp_GetExitCodeProcess(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
449 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
450 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
451 BOOL result;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
452
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
453 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
454 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
455 return NULL;
33723
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 result = GetExitCodeProcess((HANDLE) process, &exit_code);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
458
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
459 if (! result)
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
460 return PyErr_SetFromWindowsErr(GetLastError());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
461
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
462 return PyInt_FromLong(exit_code);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
463 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
464
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
465 static PyObject *
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
466 sp_WaitForSingleObject(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
467 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
468 DWORD result;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
469
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
470 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
471 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
472 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
473 &handle,
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
474 &milliseconds))
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
475 return NULL;
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 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
478 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
479 Py_END_ALLOW_THREADS
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
480
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
481 if (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
482 return PyErr_SetFromWindowsErr(GetLastError());
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 return PyInt_FromLong((int) result);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
485 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
486
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
487 static PyObject *
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
488 sp_GetVersion(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
489 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
490 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
491 return NULL;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
492
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
493 return PyInt_FromLong((int) GetVersion());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
494 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
495
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
496 static PyObject *
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
497 sp_GetModuleFileName(PyObject* self, PyObject* args)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
498 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
499 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
500 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
501 TCHAR filename[MAX_PATH];
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
502
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
503 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
504 return NULL;
33723
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 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
507 filename[MAX_PATH-1] = '\0';
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
508
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
509 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
510 return PyErr_SetFromWindowsErr(GetLastError());
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
511
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
512 return PyString_FromString(filename);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
513 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
514
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
515 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
516 {"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
517 {"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
518 {"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
519 {"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
520 {"CreateProcess", sp_CreateProcess, METH_VARARGS},
36086
e14f47964748 added TerminateProcess support to _subprocess driver
Fredrik Lundh <fredrik@pythonware.com>
parents: 36030
diff changeset
521 {"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
522 {"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
523 {"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
524 {"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
525 {"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
526 {NULL, NULL}
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
527 };
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
528
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
529 /* -------------------------------------------------------------------- */
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
530
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
531 static void
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
532 defint(PyObject* d, const char* name, int value)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
533 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
534 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
535 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
536 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
537 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
538 }
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
539 }
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
540
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
541 #if PY_VERSION_HEX >= 0x02030000
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
542 PyMODINIT_FUNC
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
543 #else
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
544 DL_EXPORT(void)
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
545 #endif
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
546 init_subprocess()
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
547 {
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
548 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
549 PyObject *m;
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
550
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
551 /* 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
552 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
553 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
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 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
556 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36086
diff changeset
557 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
558 d = PyModule_GetDict(m);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
559
33729
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
560 /* constants */
0d6d56b2164b Before this turns into an unreadable mess, follow PEP 7 by using
Tim Peters <tim.peters@gmail.com>
parents: 33723
diff changeset
561 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
562 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
563 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
564 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
565 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
566 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
567 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
568 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
569 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
570 defint(d, "CREATE_NEW_CONSOLE", CREATE_NEW_CONSOLE);
33723
76641824cf05 Added Peter Astrand's subprocess module.
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
571 }