summaryrefslogtreecommitdiffstats
path: root/Doc/library/subprocess.rst
diff options
context:
space:
mode:
authorBo Bayles <bbayles@gmail.com>2018-01-30 06:40:39 (GMT)
committerGregory P. Smith <greg@krypto.org>2018-01-30 06:40:39 (GMT)
commitce0f33d04528fcafc673a8707871f8430d8f7ce8 (patch)
treede60362ad2f3c1bb8af239c1926a7f907887e8c1 /Doc/library/subprocess.rst
parent95441809ef77a8df5e14601ade6c054ef7114c02 (diff)
downloadcpython-ce0f33d04528fcafc673a8707871f8430d8f7ce8.zip
cpython-ce0f33d04528fcafc673a8707871f8430d8f7ce8.tar.gz
cpython-ce0f33d04528fcafc673a8707871f8430d8f7ce8.tar.bz2
bpo-32102 Add "capture_output=True" to subprocess.run (GH-5149)
Add "capture_output=True" option to subprocess.run, this is equivalent to setting stdout=PIPE, stderr=PIPE but is much more readable.
Diffstat (limited to 'Doc/library/subprocess.rst')
-rw-r--r--Doc/library/subprocess.rst19
1 files changed, 11 insertions, 8 deletions
diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst
index af96f41..86f3e06 100644
--- a/Doc/library/subprocess.rst
+++ b/Doc/library/subprocess.rst
@@ -47,12 +47,14 @@ compatibility with older versions, see the :ref:`call-function-trio` section.
The arguments shown above are merely the most common ones, described below
in :ref:`frequently-used-arguments` (hence the use of keyword-only notation
in the abbreviated signature). The full function signature is largely the
- same as that of the :class:`Popen` constructor - apart from *timeout*,
- *input* and *check*, all the arguments to this function are passed through to
- that interface.
+ same as that of the :class:`Popen` constructor - most of the arguments to
+ this function are passed through to that interface. (*timeout*, *input*,
+ *check*, and *capture_output* are not.)
- This does not capture stdout or stderr by default. To do so, pass
- :data:`PIPE` for the *stdout* and/or *stderr* arguments.
+ If *capture_output* is true, stdout and stderr will be captured.
+ When used, the internal :class:`Popen` object is automatically created with
+ ``stdout=PIPE`` and ``stderr=PIPE``. The *stdout* and *stderr* arguments may
+ not be used as well.
The *timeout* argument is passed to :meth:`Popen.communicate`. If the timeout
expires, the child process will be killed and waited for. The
@@ -86,9 +88,9 @@ compatibility with older versions, see the :ref:`call-function-trio` section.
...
subprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1
- >>> subprocess.run(["ls", "-l", "/dev/null"], stdout=subprocess.PIPE)
+ >>> subprocess.run(["ls", "-l", "/dev/null"], capture_output=True)
CompletedProcess(args=['ls', '-l', '/dev/null'], returncode=0,
- stdout=b'crw-rw-rw- 1 root root 1, 3 Jan 23 16:23 /dev/null\n')
+ stdout=b'crw-rw-rw- 1 root root 1, 3 Jan 23 16:23 /dev/null\n', stderr=b'')
.. versionadded:: 3.5
@@ -98,7 +100,8 @@ compatibility with older versions, see the :ref:`call-function-trio` section.
.. versionchanged:: 3.7
- Added the *text* parameter, as a more understandable alias of *universal_newlines*
+ Added the *text* parameter, as a more understandable alias of *universal_newlines*.
+ Added the *capture_output* parameter.
.. class:: CompletedProcess