Commit 6ff05c16 authored by Gregory P. Smith's avatar Gregory P. Smith

Some cleanup of the subprocess docs in 2.7. Adds a reference to the

subprocess32 project in PyPI for posix users.
parent 7919c270
...@@ -20,20 +20,26 @@ replace several older modules and functions:: ...@@ -20,20 +20,26 @@ replace several older modules and functions::
popen2.* popen2.*
commands.* commands.*
Information about how the :mod:`subprocess` module can be used to replace these Information about how this module can be used to replace the older
modules and functions can be found in the following sections. functions can be found in the subprocess-replacements_ section.
.. seealso:: .. seealso::
POSIX users (Linux, BSD, etc.) are strongly encouraged to install
and use the much more recent subprocess32_ module instead of the
version included with python 2.7. It is a drop in replacement with
better behavior in many situations.
:pep:`324` -- PEP proposing the subprocess module :pep:`324` -- PEP proposing the subprocess module
.. _subprocess32: https://pypi.python.org/pypi/subprocess32/
Using the :mod:`subprocess` Module Using the :mod:`subprocess` Module
---------------------------------- ----------------------------------
The recommended approach to invoking subprocesses is to use the following The recommended way to launch subprocesses is to use the following
convenience functions for all use cases they can handle. For more advanced convenience functions. For more advanced use cases when these do not
use cases, the underlying :class:`Popen` interface can be used directly. meet your needs, use the underlying :class:`Popen` interface.
.. function:: call(args, *, stdin=None, stdout=None, stderr=None, shell=False) .. function:: call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
...@@ -57,16 +63,15 @@ use cases, the underlying :class:`Popen` interface can be used directly. ...@@ -57,16 +63,15 @@ use cases, the underlying :class:`Popen` interface can be used directly.
.. warning:: .. warning::
Invoking the system shell with ``shell=True`` can be a security hazard Using ``shell=True`` can be a security hazard. See the warning
if combined with untrusted input. See the warning under under :ref:`frequently-used-arguments` for details.
:ref:`frequently-used-arguments` for details.
.. note:: .. note::
Do not use ``stdout=PIPE`` or ``stderr=PIPE`` with this function. As Do not use ``stdout=PIPE`` or ``stderr=PIPE`` with this function
the pipes are not being read in the current process, the child as that can deadlock based on the child process output volume.
process may block if it generates enough output to a pipe to fill up Use :class:`Popen` with the :meth:`communicate` method when you
the OS pipe buffer. need pipes.
.. function:: check_call(args, *, stdin=None, stdout=None, stderr=None, shell=False) .. function:: check_call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
...@@ -96,16 +101,15 @@ use cases, the underlying :class:`Popen` interface can be used directly. ...@@ -96,16 +101,15 @@ use cases, the underlying :class:`Popen` interface can be used directly.
.. warning:: .. warning::
Invoking the system shell with ``shell=True`` can be a security hazard Using ``shell=True`` can be a security hazard. See the warning
if combined with untrusted input. See the warning under under :ref:`frequently-used-arguments` for details.
:ref:`frequently-used-arguments` for details.
.. note:: .. note::
Do not use ``stdout=PIPE`` or ``stderr=PIPE`` with this function. As Do not use ``stdout=PIPE`` or ``stderr=PIPE`` with this function
the pipes are not being read in the current process, the child as that can deadlock based on the child process output volume.
process may block if it generates enough output to a pipe to fill up Use :class:`Popen` with the :meth:`communicate` method when you
the OS pipe buffer. need pipes.
.. function:: check_output(args, *, stdin=None, stderr=None, shell=False, universal_newlines=False) .. function:: check_output(args, *, stdin=None, stderr=None, shell=False, universal_newlines=False)
...@@ -145,19 +149,16 @@ use cases, the underlying :class:`Popen` interface can be used directly. ...@@ -145,19 +149,16 @@ use cases, the underlying :class:`Popen` interface can be used directly.
.. versionadded:: 2.7 .. versionadded:: 2.7
..
.. warning:: .. warning::
Invoking the system shell with ``shell=True`` can be a security hazard Using ``shell=True`` can be a security hazard. See the warning
if combined with untrusted input. See the warning under under :ref:`frequently-used-arguments` for details.
:ref:`frequently-used-arguments` for details.
.. note:: .. note::
Do not use ``stderr=PIPE`` with this function. As the pipe is not being Do not use ``stderr=PIPE`` with this function as that can deadlock
read in the current process, the child process may block if it based on the child process error volume. Use :class:`Popen` with
generates enough output to the pipe to fill up the OS pipe buffer. the :meth:`communicate` method when you need a stderr pipe.
.. data:: PIPE .. data:: PIPE
...@@ -740,9 +741,9 @@ Replacing :func:`os.system` ...@@ -740,9 +741,9 @@ Replacing :func:`os.system`
:: ::
sts = os.system("mycmd" + " myarg") status = os.system("mycmd" + " myarg")
# becomes # becomes
sts = call("mycmd" + " myarg", shell=True) status = subprocess.call("mycmd" + " myarg", shell=True)
Notes: Notes:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment