blob: 9e8a0ca4ec63d36381275809fd79382ee46476b6 [file] [log] [blame]
Fred Drake6afad371998-04-28 14:28:15 +00001% This section was contributed by Drew Csillag
2% <drew_csillag@geocities.com>, with some re-organization by Fred L.
3% Drake, Jr. <fdrake@acm.org>.
4
5\section{Standard Module \module{popen2}}
6\label{module-popen2}
7\stmodindex{popen2}
8
9This module allows you to spawn processes and connect their
10input/output/error pipes and obtain their return codes.
11
12The primary interface offered by this module is a pair of factory
13functions:
14
15\begin{funcdesc}{popen2}{cmd\optional{, bufsize}}
16Executes \var{cmd} as a sub-process. If \var{bufsize} is specified,
17it specifies the buffer size for the I/O pipes. Returns
18\code{(\var{child_stdout}, \var{child_stdin})}.
19\end{funcdesc}
20
21\begin{funcdesc}{popen2}{cmd\optional{, bufsize}}
22Executes \var{cmd} as a sub-process. If \var{bufsize} is specified,
23it specifies the buffer size for the I/O pipes. Returns
24\code{(\var{child_stdout}, \var{child_stdin}, \var{child_stderr})}.
25\end{funcdesc}
26
27The class defining the objects returned by the factory functions is
28also available:
29
30\begin{classdesc}{Popen3}{cmd\optional{, capturestderr\optional{, bufsize}}}
31This class represents a child process. Normally, \class{Popen3}
32instances are created using the factory functions described above.
33
34If not using one off the helper functions to create \class{Popen3}
35objects, the parameter \var{cmd} is the shell command to execute in a
36sub-process. The \var{capturestderr} flag, if true, specifies that
37the object should capture standard error output of the child process.
38The default is false. If the \var{bufsize} parameter is specified, it
39specifies the size of the I/O buffers to/from the child process.
40\end{classdesc}
41
42
43\subsection{Popen3 Objects}
44\label{popen3-objects}
45
46Instances of the \class{Popen3} class have the following methods:
47
48\begin{methoddesc}{poll}{}
49Returns \code{-1} if child process hasn't completed yet, or its return
50code otherwise.
51\end{methoddesc}
52
53\begin{methoddesc}{wait}{}
54Waits for and returns the return code of the child process.
55\end{methoddesc}
56
57
58The following attributes of \class{Popen3} objects are also available:
59
60\begin{datadesc}{fromchild}
61A file object that provides output from the child process.
62\end{datadesc}
63
64\begin{datadesc}{tochild}
65A file object that provides input to the child process.
66\end{datadesc}
67
68\begin{datadesc}{childerr}
69Where the standard error from the child process goes is
70\var{capturestderr} was true for the constructor, or \code{None}.
71\end{datadesc}