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