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