blob: e484d236c1ae6f1e665211a68234bab563f07b14 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{popen2} ---
Fred Drake3aa70d61999-05-27 17:50:59 +00002 Subprocesses with accessible I/O streams}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drake93503ca1999-03-12 16:24:22 +00004\declaremodule{standard}{popen2}
Fred Drake5fac2ab1999-06-01 17:55:52 +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
Fred Drake5fac2ab1999-06-01 17:55:52 +000011input/output/error pipes and obtain their return codes under \UNIX.
12Similar functionality exists for Windows platforms using the
13\module{win32pipe} module provided as part of Mark Hammond's Windows
14extensions.
Fred Drake6afad371998-04-28 14:28:15 +000015
16The primary interface offered by this module is a pair of factory
17functions:
18
19\begin{funcdesc}{popen2}{cmd\optional{, bufsize}}
20Executes \var{cmd} as a sub-process. If \var{bufsize} is specified,
Fred Drake7eba1d81999-08-19 17:00:38 +000021it specifies the buffer size for the I/O pipes. Returns the file
22objects \code{(\var{child_stdout}, \var{child_stdin})}.
Fred Drake6afad371998-04-28 14:28:15 +000023\end{funcdesc}
24
Guido van Rossum3a5a02f1998-08-13 01:27:01 +000025\begin{funcdesc}{popen3}{cmd\optional{, bufsize}}
Fred Drake6afad371998-04-28 14:28:15 +000026Executes \var{cmd} as a sub-process. If \var{bufsize} is specified,
Fred Drake7eba1d81999-08-19 17:00:38 +000027it specifies the buffer size for the I/O pipes. Returns the file
28objects \code{(\var{child_stdout}, \var{child_stdin},
29\var{child_stderr})}.
Fred Drake6afad371998-04-28 14:28:15 +000030\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
Fred Drake3aa70d61999-05-27 17:50:59 +000048\subsection{Popen3 Objects \label{popen3-objects}}
Fred Drake6afad371998-04-28 14:28:15 +000049
50Instances of the \class{Popen3} class have the following methods:
51
52\begin{methoddesc}{poll}{}
53Returns \code{-1} if child process hasn't completed yet, or its return
54code otherwise.
55\end{methoddesc}
56
57\begin{methoddesc}{wait}{}
58Waits for and returns the return code of the child process.
59\end{methoddesc}
60
61
62The following attributes of \class{Popen3} objects are also available:
63
Fred Drake3aa70d61999-05-27 17:50:59 +000064\begin{memberdesc}{fromchild}
Fred Drake6afad371998-04-28 14:28:15 +000065A file object that provides output from the child process.
Fred Drake3aa70d61999-05-27 17:50:59 +000066\end{memberdesc}
Fred Drake6afad371998-04-28 14:28:15 +000067
Fred Drake3aa70d61999-05-27 17:50:59 +000068\begin{memberdesc}{tochild}
Fred Drake6afad371998-04-28 14:28:15 +000069A file object that provides input to the child process.
Fred Drake3aa70d61999-05-27 17:50:59 +000070\end{memberdesc}
Fred Drake6afad371998-04-28 14:28:15 +000071
Fred Drake3aa70d61999-05-27 17:50:59 +000072\begin{memberdesc}{childerr}
Fred Drake6afad371998-04-28 14:28:15 +000073Where the standard error from the child process goes is
74\var{capturestderr} was true for the constructor, or \code{None}.
Fred Drake3aa70d61999-05-27 17:50:59 +000075\end{memberdesc}
76
77\begin{memberdesc}{pid}
78The process ID of the child process.
79\end{memberdesc}