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