blob: 08da91012da3ec6073066e5a84d8cfa576312380 [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 Drakee3313561999-04-13 22:03:26 +00005 \platform{Unix, Windows}
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
Fred Drake3aa70d61999-05-27 17:50:59 +000044\subsection{Popen3 Objects \label{popen3-objects}}
Fred Drake6afad371998-04-28 14:28:15 +000045
46Instances of the \class{Popen3} class have the following methods:
47
48\begin{methoddesc}{poll}{}
49Returns \code{-1} if child process hasn't completed yet, or its return
50code otherwise.
51\end{methoddesc}
52
53\begin{methoddesc}{wait}{}
54Waits for and returns the return code of the child process.
55\end{methoddesc}
56
57
58The following attributes of \class{Popen3} objects are also available:
59
Fred Drake3aa70d61999-05-27 17:50:59 +000060\begin{memberdesc}{fromchild}
Fred Drake6afad371998-04-28 14:28:15 +000061A file object that provides output from the child process.
Fred Drake3aa70d61999-05-27 17:50:59 +000062\end{memberdesc}
Fred Drake6afad371998-04-28 14:28:15 +000063
Fred Drake3aa70d61999-05-27 17:50:59 +000064\begin{memberdesc}{tochild}
Fred Drake6afad371998-04-28 14:28:15 +000065A file object that provides input to 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}{childerr}
Fred Drake6afad371998-04-28 14:28:15 +000069Where the standard error from the child process goes is
70\var{capturestderr} was true for the constructor, or \code{None}.
Fred Drake3aa70d61999-05-27 17:50:59 +000071\end{memberdesc}
72
73\begin{memberdesc}{pid}
74The process ID of the child process.
75\end{memberdesc}