blob: 71c4631849e9deec5333bc0065af82b9c2efbbc5 [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,
21it specifies the buffer size for the I/O pipes. Returns
22\code{(\var{child_stdout}, \var{child_stdin})}.
23\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,
27it specifies the buffer size for the I/O pipes. Returns
28\code{(\var{child_stdout}, \var{child_stdin}, \var{child_stderr})}.
29\end{funcdesc}
30
31The class defining the objects returned by the factory functions is
32also available:
33
34\begin{classdesc}{Popen3}{cmd\optional{, capturestderr\optional{, bufsize}}}
35This class represents a child process. Normally, \class{Popen3}
36instances are created using the factory functions described above.
37
38If not using one off the helper functions to create \class{Popen3}
39objects, the parameter \var{cmd} is the shell command to execute in a
40sub-process. The \var{capturestderr} flag, if true, specifies that
41the object should capture standard error output of the child process.
42The default is false. If the \var{bufsize} parameter is specified, it
43specifies the size of the I/O buffers to/from the child process.
44\end{classdesc}
45
46
Fred Drake3aa70d61999-05-27 17:50:59 +000047\subsection{Popen3 Objects \label{popen3-objects}}
Fred Drake6afad371998-04-28 14:28:15 +000048
49Instances of the \class{Popen3} class have the following methods:
50
51\begin{methoddesc}{poll}{}
52Returns \code{-1} if child process hasn't completed yet, or its return
53code otherwise.
54\end{methoddesc}
55
56\begin{methoddesc}{wait}{}
57Waits for and returns the return code of the child process.
58\end{methoddesc}
59
60
61The following attributes of \class{Popen3} objects are also available:
62
Fred Drake3aa70d61999-05-27 17:50:59 +000063\begin{memberdesc}{fromchild}
Fred Drake6afad371998-04-28 14:28:15 +000064A file object that provides output from the child process.
Fred Drake3aa70d61999-05-27 17:50:59 +000065\end{memberdesc}
Fred Drake6afad371998-04-28 14:28:15 +000066
Fred Drake3aa70d61999-05-27 17:50:59 +000067\begin{memberdesc}{tochild}
Fred Drake6afad371998-04-28 14:28:15 +000068A file object that provides input to the child process.
Fred Drake3aa70d61999-05-27 17:50:59 +000069\end{memberdesc}
Fred Drake6afad371998-04-28 14:28:15 +000070
Fred Drake3aa70d61999-05-27 17:50:59 +000071\begin{memberdesc}{childerr}
Fred Drake6afad371998-04-28 14:28:15 +000072Where the standard error from the child process goes is
73\var{capturestderr} was true for the constructor, or \code{None}.
Fred Drake3aa70d61999-05-27 17:50:59 +000074\end{memberdesc}
75
76\begin{memberdesc}{pid}
77The process ID of the child process.
78\end{memberdesc}