Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:6.7.1 The dircmp classUp:6. Generic Operating SystemNext:6.8.1 Popen3 and Popen4

6.8popen2 -- Subprocesses with accessible I/O streams

Availability:Unix, Windows.

This module allows you to spawn processes and connect to theirinput/output/error pipes and obtain their return codes underUnix and Windows.

Note that starting with Python 2.0, this functionality is availableusing functions from theos module which have the samenames as the factory functions here, but the order of the returnvalues is more intuitive in theos module variants.

The primary interface offered by this module is a trio of factoryfunctions. For each of these, ifbufsize is specified, it specifies the buffer size for the I/O pipes.mode, ifprovided, should be the string'b' or't'; on Windowsthis is needed to determine whether the file objects should be openedin binary or text mode. The default value formode is't'.

The only way to retrieve the return codes for the child processes isby using thepoll() orwait() methods on thePopen3 andPopen4 classes; these are only available onUnix. This information is not available when using thepopen2(),popen3(), andpopen4()functions, or the equivalent functions in theos module.

popen2(cmd[, bufsize[, mode]])
Executescmd as a sub-process. Returns the file objects(child_stdout,child_stdin).

popen3(cmd[, bufsize[, mode]])
Executescmd as a sub-process. Returns the file objects(child_stdout,child_stdin,child_stderr).

popen4(cmd[, bufsize[, mode]])
Executescmd 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 factoryfunctions is also available. These are not used for the Windowsimplementation, and are not available on that platform.

classPopen3(cmd[, capturestderr[, bufsize]])
This class represents a child process. Normally,Popen3instances are created using thepopen2() andpopen3() factory functions described above.

If not using one off the helper functions to createPopen3objects, the parametercmd is the shell command to execute in asub-process. Thecapturestderr flag, if true, specifies thatthe object should capture standard error output of the child process.The default is false. If thebufsize parameter is specified, itspecifies the size of the I/O buffers to/from the child process.

classPopen4(cmd[, bufsize])
Similar toPopen3, but always captures standard error into thesame file object as standard output. These are typically createdusingpopen4().New in version 2.0.


Subsections


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:6.7.1 The dircmp classUp:6. Generic Operating SystemNext:6.8.1 Popen3 and Popen4
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp