[issue6445] Add check parameter to subprocess.Popen.communicate

akira report at bugs.python.org
Fri May 16 18:55:34 CEST 2014


akira added the comment:

subprocess.check_output() could be used in "communicate() + check process
exit status" one-liners. It returns child process output (stdout)
and raises an exception if the returncode is not zero. It is available
since Python 2.7 (3.1)

If you don't want to raise an error for non-zero exit status; you
could define a helper function:

  def status_output(*args, **kwargs):
      try:
          return 0, check_output(*args, **kwargs)
      except CalledProcessError as e:
          return e.returncode, e.output


> The CalledProcessError requires a cmd argument, which means also adding
a cmd member to Popen objects.

Popen.args is available since Python 3.3, see issue #21353

----------
nosy: +akira

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6445>
_______________________________________


More information about the Python-bugs-list mailing list