blob: d2cc0fdf4dbc0fa202da7f642597b14f35eb12eb [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{popen2} ---
Fred Drakef6863c11999-03-02 16:37:17 +00002 Subprocesses with accessible standard I/O streams}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drake93503ca1999-03-12 16:24:22 +00004\declaremodule{standard}{popen2}
Fred Drakea54a8871999-03-02 17:03:42 +00005 \platform{Unix}
Fred Drakea30e4691998-07-27 22:20:02 +00006\modulesynopsis{Subprocesses with accessible standard I/O streams.}
Fred Drakef6863c11999-03-02 16:37:17 +00007\sectionauthor{Drew Csillag}{drew_csillag@geocities.com}
Fred Drakeb91e9341998-07-23 17:59:49 +00008
Fred Drake6afad371998-04-28 14:28:15 +00009
10This module allows you to spawn processes and connect their
11input/output/error pipes and obtain their return codes.
12
13The primary interface offered by this module is a pair of factory
14functions:
15
16\begin{funcdesc}{popen2}{cmd\optional{, bufsize}}
17Executes \var{cmd} as a sub-process. If \var{bufsize} is specified,
18it specifies the buffer size for the I/O pipes. Returns
19\code{(\var{child_stdout}, \var{child_stdin})}.
20\end{funcdesc}
21
Guido van Rossum3a5a02f1998-08-13 01:27:01 +000022\begin{funcdesc}{popen3}{cmd\optional{, bufsize}}
Fred Drake6afad371998-04-28 14:28:15 +000023Executes \var{cmd} as a sub-process. If \var{bufsize} is specified,
24it specifies the buffer size for the I/O pipes. Returns
25\code{(\var{child_stdout}, \var{child_stdin}, \var{child_stderr})}.
26\end{funcdesc}
27
28The class defining the objects returned by the factory functions is
29also available:
30
31\begin{classdesc}{Popen3}{cmd\optional{, capturestderr\optional{, bufsize}}}
32This class represents a child process. Normally, \class{Popen3}
33instances are created using the factory functions described above.
34
35If not using one off the helper functions to create \class{Popen3}
36objects, the parameter \var{cmd} is the shell command to execute in a
37sub-process. The \var{capturestderr} flag, if true, specifies that
38the object should capture standard error output of the child process.
39The default is false. If the \var{bufsize} parameter is specified, it
40specifies the size of the I/O buffers to/from the child process.
41\end{classdesc}
42
43
44\subsection{Popen3 Objects}
45\label{popen3-objects}
46
47Instances of the \class{Popen3} class have the following methods:
48
49\begin{methoddesc}{poll}{}
50Returns \code{-1} if child process hasn't completed yet, or its return
51code otherwise.
52\end{methoddesc}
53
54\begin{methoddesc}{wait}{}
55Waits for and returns the return code of the child process.
56\end{methoddesc}
57
58
59The following attributes of \class{Popen3} objects are also available:
60
61\begin{datadesc}{fromchild}
62A file object that provides output from the child process.
63\end{datadesc}
64
65\begin{datadesc}{tochild}
66A file object that provides input to the child process.
67\end{datadesc}
68
69\begin{datadesc}{childerr}
70Where the standard error from the child process goes is
71\var{capturestderr} was true for the constructor, or \code{None}.
72\end{datadesc}