summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libpopen2.tex
blob: e484d236c1ae6f1e665211a68234bab563f07b14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
\section{\module{popen2} ---
         Subprocesses with accessible I/O streams}

\declaremodule{standard}{popen2}
  \platform{Unix}
\modulesynopsis{Subprocesses with accessible standard I/O streams.}
\sectionauthor{Drew Csillag}{drew_csillag@geocities.com}


This module allows you to spawn processes and connect their 
input/output/error pipes and obtain their return codes under \UNIX.
Similar functionality exists for Windows platforms using the
\module{win32pipe} module provided as part of Mark Hammond's Windows
extensions.

The primary interface offered by this module is a pair of factory
functions:

\begin{funcdesc}{popen2}{cmd\optional{, bufsize}}
Executes \var{cmd} as a sub-process.  If \var{bufsize} is specified, 
it specifies the buffer size for the I/O pipes.  Returns the file
objects \code{(\var{child_stdout}, \var{child_stdin})}.
\end{funcdesc}

\begin{funcdesc}{popen3}{cmd\optional{, bufsize}}
Executes \var{cmd} as a sub-process.  If \var{bufsize} is specified, 
it specifies the buffer size for the I/O pipes.  Returns the file
objects \code{(\var{child_stdout}, \var{child_stdin},
\var{child_stderr})}.
\end{funcdesc}

The class defining the objects returned by the factory functions is
also available:

\begin{classdesc}{Popen3}{cmd\optional{, capturestderr\optional{, bufsize}}}
This class represents a child process.  Normally, \class{Popen3}
instances are created using the factory functions described above.

If not using one off the helper functions to create \class{Popen3}
objects, the parameter \var{cmd} is the shell command to execute in a
sub-process.  The \var{capturestderr} flag, if true, specifies that
the object should capture standard error output of the child process.
The default is false.  If the \var{bufsize} parameter is specified, it
specifies the size of the I/O buffers to/from the child process.
\end{classdesc}


\subsection{Popen3 Objects \label{popen3-objects}}

Instances of the \class{Popen3} class have the following methods:

\begin{methoddesc}{poll}{}
Returns \code{-1} if child process hasn't completed yet, or its return 
code otherwise.
\end{methoddesc}

\begin{methoddesc}{wait}{}
Waits for and returns the return code of the child process.
\end{methoddesc}


The following attributes of \class{Popen3} objects are also available: 

\begin{memberdesc}{fromchild}
A file object that provides output from the child process.
\end{memberdesc}

\begin{memberdesc}{tochild}
A file object that provides input to the child process.
\end{memberdesc}

\begin{memberdesc}{childerr}
Where the standard error from the child process goes is
\var{capturestderr} was true for the constructor, or \code{None}.
\end{memberdesc}

\begin{memberdesc}{pid}
The process ID of the child process.
\end{memberdesc}