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