| 
									
										
										
										
											1998-08-10 19:42:37 +00:00
										 |  |  | \section{\module{popen2} --- | 
					
						
							| 
									
										
										
										
											1999-05-27 17:50:59 +00:00
										 |  |  |          Subprocesses with accessible I/O streams} | 
					
						
							| 
									
										
										
										
											1998-08-10 19:42:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-03-12 16:24:22 +00:00
										 |  |  | \declaremodule{standard}{popen2} | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  |   \platform{Unix, Windows} | 
					
						
							| 
									
										
										
										
											1998-07-27 22:20:02 +00:00
										 |  |  | \modulesynopsis{Subprocesses with accessible standard I/O streams.} | 
					
						
							| 
									
										
										
										
											1999-03-02 16:37:17 +00:00
										 |  |  | \sectionauthor{Drew Csillag}{drew_csillag@geocities.com} | 
					
						
							| 
									
										
										
										
											1998-07-23 17:59:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  | This module allows you to spawn processes and connect to their | 
					
						
							|  |  |  | input/output/error pipes and obtain their return codes under | 
					
						
							|  |  |  | \UNIX{} and Windows. | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  | Note that starting with Python 2.0, this functionality is available | 
					
						
							|  |  |  | using functions from the \refmodule{os} module which have the same | 
					
						
							|  |  |  | names as the factory functions here, but the order of the return | 
					
						
							|  |  |  | values is more intuitive in the \refmodule{os} module variants. | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  | The primary interface offered by this module is a trio of factory | 
					
						
							|  |  |  | functions.  For each of these, if \var{bufsize} is specified,  | 
					
						
							|  |  |  | it specifies the buffer size for the I/O pipes.  \var{mode}, if | 
					
						
							|  |  |  | provided, should be the string \code{'b'} or \code{'t'}; on Windows | 
					
						
							|  |  |  | this is needed to determine whether the file objects should be opened | 
					
						
							|  |  |  | in binary or text mode.  The default value for \var{mode} is | 
					
						
							|  |  |  | \code{'t'}. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{popen2}{cmd\optional{, bufsize\optional{, mode}}} | 
					
						
							|  |  |  | Executes \var{cmd} as a sub-process.  Returns the file objects | 
					
						
							|  |  |  | \code{(\var{child_stdout}, \var{child_stdin})}. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{popen3}{cmd\optional{, bufsize\optional{, mode}}} | 
					
						
							|  |  |  | Executes \var{cmd} as a sub-process.  Returns the file objects | 
					
						
							|  |  |  | \code{(\var{child_stdout}, \var{child_stdin}, \var{child_stderr})}. | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  | \begin{funcdesc}{popen4}{cmd\optional{, bufsize\optional{, mode}}} | 
					
						
							|  |  |  | Executes \var{cmd} as a sub-process.  Returns the file objects | 
					
						
							|  |  |  | \code{(\var{child_stdout_and_stderr}, \var{child_stdin})}. | 
					
						
							|  |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | On \UNIX, a class defining the objects returned by the factory | 
					
						
							|  |  |  | functions is also available.  These are not used for the Windows | 
					
						
							|  |  |  | implementation, and are not available on that platform. | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | \begin{classdesc}{Popen3}{cmd\optional{, capturestderr\optional{, bufsize}}} | 
					
						
							|  |  |  | This class represents a child process.  Normally, \class{Popen3} | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  | instances are created using the \function{popen2()} and | 
					
						
							|  |  |  | \function{popen3()} factory functions described above. | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  | \begin{classdesc}{Popen4}{cmd\optional{, bufsize}} | 
					
						
							|  |  |  | Similar to \class{Popen3}, but always captures standard error into the | 
					
						
							|  |  |  | same file object as standard output.  These are typically created | 
					
						
							|  |  |  | using \function{popen4()}. | 
					
						
							|  |  |  | \versionadded{2.0} | 
					
						
							|  |  |  | \end{classdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  | \subsection{Popen3 and Popen4 Objects \label{popen3-objects}} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  | Instances of the \class{Popen3} and \class{Popen4} classes have the | 
					
						
							|  |  |  | following methods: | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | \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} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  | The following attributes are also available:  | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-05-27 17:50:59 +00:00
										 |  |  | \begin{memberdesc}{fromchild} | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  | A file object that provides output from the child process.  For | 
					
						
							|  |  |  | \class{Popen4} instances, this will provide both the standard output | 
					
						
							|  |  |  | and standard error streams. | 
					
						
							| 
									
										
										
										
											1999-05-27 17:50:59 +00:00
										 |  |  | \end{memberdesc} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-05-27 17:50:59 +00:00
										 |  |  | \begin{memberdesc}{tochild} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | A file object that provides input to the child process. | 
					
						
							| 
									
										
										
										
											1999-05-27 17:50:59 +00:00
										 |  |  | \end{memberdesc} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-05-27 17:50:59 +00:00
										 |  |  | \begin{memberdesc}{childerr} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | Where the standard error from the child process goes is | 
					
						
							|  |  |  | \var{capturestderr} was true for the constructor, or \code{None}. | 
					
						
							| 
									
										
										
										
											2000-09-28 20:27:51 +00:00
										 |  |  | This will always be \code{None} for \class{Popen4} instances. | 
					
						
							| 
									
										
										
										
											1999-05-27 17:50:59 +00:00
										 |  |  | \end{memberdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{memberdesc}{pid} | 
					
						
							|  |  |  | The process ID of the child process. | 
					
						
							|  |  |  | \end{memberdesc} |