| 
									
										
										
										
											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} | 
					
						
							| 
									
										
										
										
											1999-06-01 17:55:52 +00:00
										 |  |  |   \platform{Unix} | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | This module allows you to spawn processes and connect their  | 
					
						
							| 
									
										
										
										
											1999-06-01 17:55:52 +00:00
										 |  |  | 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. | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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 | 
					
						
							|  |  |  | \code{(\var{child_stdout}, \var{child_stdin})}. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-08-13 01:27:01 +00:00
										 |  |  | \begin{funcdesc}{popen3}{cmd\optional{, bufsize}} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | Executes \var{cmd} as a sub-process.  If \var{bufsize} is specified,  | 
					
						
							|  |  |  | it specifies the buffer size for the I/O pipes.  Returns | 
					
						
							|  |  |  | \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} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-05-27 17:50:59 +00:00
										 |  |  | \subsection{Popen3 Objects \label{popen3-objects}} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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:  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-05-27 17:50:59 +00:00
										 |  |  | \begin{memberdesc}{fromchild} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:15 +00:00
										 |  |  | A file object that provides output from 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}{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}. | 
					
						
							| 
									
										
										
										
											1999-05-27 17:50:59 +00:00
										 |  |  | \end{memberdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{memberdesc}{pid} | 
					
						
							|  |  |  | The process ID of the child process. | 
					
						
							|  |  |  | \end{memberdesc} |