Index: Doc/library/subprocess.rst =================================================================== --- Doc/library/subprocess.rst (revision 76868) +++ Doc/library/subprocess.rst (working copy) @@ -162,7 +162,8 @@ The arguments are the same as for the Popen constructor. Example:: - retcode = call(["ls", "-l"]) + >>> import subprocess + >>> retcode = subprocess.call(["ls", "-l"]) .. warning:: @@ -181,7 +182,9 @@ The arguments are the same as for the Popen constructor. Example:: - check_call(["ls", "-l"]) + >>> import subprocess + >>> subprocess.check_call(["ls", "-l"]) + 0 .. versionadded:: 2.5 @@ -201,6 +204,7 @@ The arguments are the same as for the :class:`Popen` constructor. Example:: + >>> import subprocess >>> subprocess.check_output(["ls", "-l", "/dev/null"]) 'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n' @@ -208,8 +212,8 @@ 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 Index: Lib/subprocess.py =================================================================== --- Lib/subprocess.py (revision 76868) +++ Lib/subprocess.py (working copy) @@ -115,7 +115,7 @@ The arguments are the same as for the Popen constructor. Example: - retcode = call(["ls", "-l"]) + >>> retcode = call(["ls", "-l"]) check_call(*popenargs, **kwargs): Run command with arguments. Wait for command to complete. If the @@ -125,18 +125,20 @@ The arguments are the same as for the Popen constructor. Example: - check_call(["ls", "-l"]) + >>> check_call(["ls", "-l"]) + 0 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 = check_output(["ls", "-l", "/dev/null"]) - output = subprocess.check_output(["ls", "-l", "/dev/null"]) Exceptions ---------- @@ -462,7 +464,8 @@ def _cleanup(): for inst in _active[:]: - if inst._internal_poll(_deadstate=sys.maxint) >= 0: + res = inst._internal_poll(_deadstate=sys.maxint) + if res is not None and res >= 0: try: _active.remove(inst) except ValueError: @@ -505,11 +508,11 @@ 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 - attribute and output in the output attribute. + 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: @@ -517,11 +520,11 @@ 'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n' The stdout argument is not allowed as it is used internally. - To capture standard error in the result, use stderr=subprocess.STDOUT. + To capture standard error in the result, use stderr=STDOUT. >>> check_output(["/bin/sh", "-c", - "ls -l non_existent_file ; exit 0"], - stderr=subprocess.STDOUT) + ... "ls -l non_existent_file ; exit 0"], + ... stderr=STDOUT) 'ls: non_existent_file: No such file or directory\n' """ if 'stdout' in kwargs: