# 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'`.

`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.

`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 off 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.

`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.

Subsections

- 6.8.1 Popen3 and Popen4 Objects