subprocess: unexpected keyword argument capture_output
You inspected the wrong documentation, for python-3.6 this parameter does not exist, as can be found in the documentation (you select the version at the top left):
subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, shell=False, cwd=None, timeout=None, check=False, encoding=None, errors=None, env=None)
You can however easily "emulate" this by setting both stdout
and stderr
to PIPE
:
from subprocess import PIPE
subprocess.run(["ls", "-l", "/dev/null"], stdout=PIPE, stderr=PIPE)
In fact, if we look at the source code of the python-3.7 version, where the feature was introduced, we see in the source code [GitHub]:
if capture_output: if ('stdout' in kwargs) or ('stderr' in kwargs): raise ValueError('stdout and stderr arguments may not be used ' 'with capture_output.') kwargs['stdout'] = PIPE kwargs['stderr'] = PIPE
The simplest method is to use the subprocess.check_output function:
import subprocess
subprocess.check_output(["ls", "-l", "/dev/null"])