Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-datetime.html" /> | |
13 | <link rel="prev" href="module-subprocess.html" /> | |
14 | <link rel="parent" href="allos.html" /> | |
15 | <link rel="next" href="popen3-objects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>6.9 popen2 -- Subprocesses with accessible I/O streams</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="6.8.3.6 Replacing popen2.*" | |
25 | href="node246.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
28 | href="allos.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="6.9.1 Popen3 and Popen4" | |
31 | href="popen3-objects.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="node246.html">6.8.3.6 Replacing popen2.*</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="popen3-objects.html">6.9.1 Popen3 and Popen4</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION008900000000000000000"> | |
56 | 6.9 <tt class="module">popen2</tt> -- | |
57 | Subprocesses with accessible I/O streams</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-popen2"></A> | |
62 | <p class="availability">Availability: <span | |
63 | class="platform">Unix, Windows</span>.</p> | |
64 | ||
65 | <P> | |
66 | This module allows you to spawn processes and connect to their | |
67 | input/output/error pipes and obtain their return codes under | |
68 | <span class="Unix">Unix</span> and Windows. | |
69 | ||
70 | <P> | |
71 | Note that starting with Python 2.0, this functionality is available | |
72 | using functions from the <tt class="module"><a href="module-os.html">os</a></tt> module which have the same | |
73 | names as the factory functions here, but the order of the return | |
74 | values is more intuitive in the <tt class="module"><a href="module-os.html">os</a></tt> module variants. | |
75 | ||
76 | <P> | |
77 | The primary interface offered by this module is a trio of factory | |
78 | functions. For each of these, if <var>bufsize</var> is specified, | |
79 | it specifies the buffer size for the I/O pipes. <var>mode</var>, if | |
80 | provided, should be the string <code>'b'</code> or <code>'t'</code>; on Windows | |
81 | this is needed to determine whether the file objects should be opened | |
82 | in binary or text mode. The default value for <var>mode</var> is | |
83 | <code>'t'</code>. | |
84 | ||
85 | <P> | |
86 | On <span class="Unix">Unix</span>, <var>cmd</var> may be a sequence, in which case arguments will be passed | |
87 | directly to the program without shell intervention (as with | |
88 | <tt class="function">os.spawnv()</tt>). If <var>cmd</var> is a string it will be passed to the | |
89 | shell (as with <tt class="function">os.system()</tt>). | |
90 | ||
91 | <P> | |
92 | The only way to retrieve the return codes for the child processes is | |
93 | by using the <tt class="method">poll()</tt> or <tt class="method">wait()</tt> methods on the | |
94 | <tt class="class">Popen3</tt> and <tt class="class">Popen4</tt> classes; these are only available on | |
95 | <span class="Unix">Unix</span>. This information is not available when using the | |
96 | <tt class="function">popen2()</tt>, <tt class="function">popen3()</tt>, and <tt class="function">popen4()</tt> | |
97 | functions, or the equivalent functions in the <tt class="module"><a href="module-os.html">os</a></tt> module. | |
98 | (Note that the tuples returned by the <tt class="module"><a href="module-os.html">os</a></tt> module's functions | |
99 | are in a different order from the ones returned by the <tt class="module">popen2</tt> | |
100 | module.) | |
101 | ||
102 | <P> | |
103 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
104 | <td><nobr><b><tt id='l2h-1844' xml:id='l2h-1844' class="function">popen2</tt></b>(</nobr></td> | |
105 | <td><var>cmd</var><big>[</big><var>, bufsize</var><big>[</big><var>, mode</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
106 | <dd> | |
107 | Executes <var>cmd</var> as a sub-process. Returns the file objects | |
108 | <code>(<var>child_stdout</var>, <var>child_stdin</var>)</code>. | |
109 | </dl> | |
110 | ||
111 | <P> | |
112 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
113 | <td><nobr><b><tt id='l2h-1845' xml:id='l2h-1845' class="function">popen3</tt></b>(</nobr></td> | |
114 | <td><var>cmd</var><big>[</big><var>, bufsize</var><big>[</big><var>, mode</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
115 | <dd> | |
116 | Executes <var>cmd</var> as a sub-process. Returns the file objects | |
117 | <code>(<var>child_stdout</var>, <var>child_stdin</var>, <var>child_stderr</var>)</code>. | |
118 | </dl> | |
119 | ||
120 | <P> | |
121 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
122 | <td><nobr><b><tt id='l2h-1846' xml:id='l2h-1846' class="function">popen4</tt></b>(</nobr></td> | |
123 | <td><var>cmd</var><big>[</big><var>, bufsize</var><big>[</big><var>, mode</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
124 | <dd> | |
125 | Executes <var>cmd</var> as a sub-process. Returns the file objects | |
126 | <code>(<var>child_stdout_and_stderr</var>, <var>child_stdin</var>)</code>. | |
127 | ||
128 | <span class="versionnote">New in version 2.0.</span> | |
129 | ||
130 | </dl> | |
131 | ||
132 | <P> | |
133 | On <span class="Unix">Unix</span>, a class defining the objects returned by the factory | |
134 | functions is also available. These are not used for the Windows | |
135 | implementation, and are not available on that platform. | |
136 | ||
137 | <P> | |
138 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
139 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-1847' xml:id='l2h-1847' class="class">Popen3</tt></b>(</nobr></td> | |
140 | <td><var>cmd</var><big>[</big><var>, capturestderr</var><big>[</big><var>, bufsize</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
141 | <dd> | |
142 | This class represents a child process. Normally, <tt class="class">Popen3</tt> | |
143 | instances are created using the <tt class="function">popen2()</tt> and | |
144 | <tt class="function">popen3()</tt> factory functions described above. | |
145 | ||
146 | <P> | |
147 | If not using one of the helper functions to create <tt class="class">Popen3</tt> | |
148 | objects, the parameter <var>cmd</var> is the shell command to execute in a | |
149 | sub-process. The <var>capturestderr</var> flag, if true, specifies that | |
150 | the object should capture standard error output of the child process. | |
151 | The default is false. If the <var>bufsize</var> parameter is specified, it | |
152 | specifies the size of the I/O buffers to/from the child process. | |
153 | </dl> | |
154 | ||
155 | <P> | |
156 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
157 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-1848' xml:id='l2h-1848' class="class">Popen4</tt></b>(</nobr></td> | |
158 | <td><var>cmd</var><big>[</big><var>, bufsize</var><big>]</big><var></var>)</td></tr></table></dt> | |
159 | <dd> | |
160 | Similar to <tt class="class">Popen3</tt>, but always captures standard error into the | |
161 | same file object as standard output. These are typically created | |
162 | using <tt class="function">popen4()</tt>. | |
163 | ||
164 | <span class="versionnote">New in version 2.0.</span> | |
165 | ||
166 | </dl> | |
167 | ||
168 | <P> | |
169 | ||
170 | <p><br /></p><hr class='online-navigation' /> | |
171 | <div class='online-navigation'> | |
172 | <!--Table of Child-Links--> | |
173 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
174 | ||
175 | <UL CLASS="ChildLinks"> | |
176 | <LI><A href="popen3-objects.html">6.9.1 Popen3 and Popen4 Objects</a> | |
177 | <LI><A href="popen2-flow-control.html">6.9.2 Flow Control Issues</a> | |
178 | </ul> | |
179 | <!--End of Table of Child-Links--> | |
180 | </div> | |
181 | ||
182 | <DIV CLASS="navigation"> | |
183 | <div class='online-navigation'> | |
184 | <p></p><hr /> | |
185 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
186 | <tr> | |
187 | <td class='online-navigation'><a rel="prev" title="6.8.3.6 Replacing popen2.*" | |
188 | href="node246.html"><img src='../icons/previous.png' | |
189 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
190 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
191 | href="allos.html"><img src='../icons/up.png' | |
192 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
193 | <td class='online-navigation'><a rel="next" title="6.9.1 Popen3 and Popen4" | |
194 | href="popen3-objects.html"><img src='../icons/next.png' | |
195 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
196 | <td align="center" width="100%">Python Library Reference</td> | |
197 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
198 | href="contents.html"><img src='../icons/contents.png' | |
199 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
200 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
201 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
202 | <td class='online-navigation'><a rel="index" title="Index" | |
203 | href="genindex.html"><img src='../icons/index.png' | |
204 | border='0' height='32' alt='Index' width='32' /></A></td> | |
205 | </tr></table> | |
206 | <div class='online-navigation'> | |
207 | <b class="navlabel">Previous:</b> | |
208 | <a class="sectref" rel="prev" href="node246.html">6.8.3.6 Replacing popen2.*</A> | |
209 | <b class="navlabel">Up:</b> | |
210 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
211 | <b class="navlabel">Next:</b> | |
212 | <a class="sectref" rel="next" href="popen3-objects.html">6.9.1 Popen3 and Popen4</A> | |
213 | </div> | |
214 | </div> | |
215 | <hr /> | |
216 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
217 | </DIV> | |
218 | <!--End of Navigation Panel--> | |
219 | <ADDRESS> | |
220 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
221 | </ADDRESS> | |
222 | </BODY> | |
223 | </HTML> |