.. note::
- This feature is only available if Python is built with universal newline support
- (the default). Also, the newlines attribute of the file objects :attr:`stdout`,
- :attr:`stdin` and :attr:`stderr` are not updated by the communicate() method.
+ This feature is only available if Python is built with universal newline
+ support (the default). Also, the newlines attribute of the file objects
+ :attr:`stdout`, :attr:`stdin` and :attr:`stderr` are not updated by the
+ communicate() method.
The *startupinfo* and *creationflags*, if given, will be passed to the
underlying CreateProcess() function. They can specify things such as appearance
The arguments are the same as for the Popen constructor. Example::
- retcode = call(["ls", "-l"])
+ >>> retcode = subprocess.call(["ls", "-l"])
.. warning::
The arguments are the same as for the Popen constructor. Example::
- check_call(["ls", "-l"])
+ >>> subprocess.check_call(["ls", "-l"])
+ 0
.. versionadded:: 2.5
To capture standard error in the result, use ``stderr=subprocess.STDOUT``::
>>> subprocess.check_output(
- ["/bin/sh", "-c", "ls non_existent_file ; exit 0"],
- stderr=subprocess.STDOUT)
+ ... ["/bin/sh", "-c", "ls non_existent_file; exit 0"],
+ ... stderr=subprocess.STDOUT)
'ls: non_existent_file: No such file or directory\n'
.. versionadded:: 2.7
check_call(["ls", "-l"])
check_output(*popenargs, **kwargs):
- Run command with arguments and return its output as a byte string.
+ Run command with arguments and return its output as a byte string.
- If the exit code was non-zero it raises a CalledProcessError. The
- CalledProcessError object will have the return code in the returncode
- attribute and output in the output attribute.
+ If the exit code was non-zero it raises a CalledProcessError. The
+ CalledProcessError object will have the return code in the returncode
+ attribute and output in the output attribute.
- The arguments are the same as for the Popen constructor. Example:
+ The arguments are the same as for the Popen constructor. Example:
- output = subprocess.check_output(["ls", "-l", "/dev/null"])
+ output = subprocess.check_output(["ls", "-l", "/dev/null"])
Exceptions
----------
def check_output(*popenargs, **kwargs):
- """Run command with arguments and return its output as a byte string.
+ r"""Run command with arguments and return its output as a byte string.
If the exit code was non-zero it raises a CalledProcessError. The
CalledProcessError object will have the return code in the returncode
To capture standard error in the result, use stderr=subprocess.STDOUT.
>>> check_output(["/bin/sh", "-c",
- "ls -l non_existent_file ; exit 0"],
- stderr=subprocess.STDOUT)
+ ... "ls -l non_existent_file ; exit 0"],
+ ... stderr=subprocess.STDOUT)
'ls: non_existent_file: No such file or directory\n'
"""
if 'stdout' in kwargs: