Website hosting service by Active-Venture.com
  

 Back to Index

6.8 popen2 -- Subprocesses with accessible I/O streams

Availability: Unix, Windows.

This module allows you to spawn processes and connect to their input/output/error pipes and obtain their return codes under Unix and Windows.

Note that starting with Python 2.0, this functionality is available using functions from the os module which have the same names as the factory functions here, but the order of the return values is more intuitive in the os module variants.

The primary interface offered by this module is a trio of factory functions. For each of these, if bufsize is specified, it specifies the buffer size for the I/O pipes. mode, if provided, should be the string 'b' or 't'; on Windows this is needed to determine whether the file objects should be opened in binary or text mode. The default value for mode is 't'.

The only way to retrieve the return codes for the child processes is by using the poll() or wait() methods on the Popen3 and Popen4 classes; these are only available on Unix. This information is not available when using the popen2(), popen3(), and popen4() functions, or the equivalent functions in the os module.

 
popen2( cmd[, bufsize[, mode]])
Executes cmd as a sub-process. Returns the file objects (child_stdout, child_stdin).
 
popen3( cmd[, bufsize[, mode]])
Executes cmd as a sub-process. Returns the file objects (child_stdout, child_stdin, child_stderr).
 
popen4( cmd[, bufsize[, mode]])
Executes cmd as a sub-process. Returns the file objects (child_stdout_and_stderr, child_stdin). New in version 2.0.

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.

 
class Popen3( cmd[, capturestderr[, bufsize]])
This class represents a child process. Normally, Popen3 instances are created using the popen2() and popen3() factory functions described above.

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

 
class Popen4( cmd[, bufsize])
Similar to Popen3, but always captures standard error into the same file object as standard output. These are typically created using popen4(). New in version 2.0.

 


  

 

2002-2004 Active-Venture.com Webhosting Service

 

Disclaimer: This documentation is provided only for the benefits of our hosting customers.
For authoritative source of the documentation, please refer to http://python.org/doc/

 

Cheap domain registrar provides cheap domain registration, buy domain name and domain transfer from $5.95/year only   Cheap domain registration : Buy domain name and enjoy comprehensive free services