Hi I am newbie to Python and am trying to understand how stderr is used with subprocess check_output. I've read through the subprocess documentation and am having difficulty understanding how the stderr is used and what specifically subprocess.STDOUT
actually accomplishes.
Can I please get some help with some examples or references that explains how stderr is used here?
I've tried these commands using both stderr and without and not seeing any real difference.
Code:
#!/usr/bin/python3
import subprocess
print(subprocess.check_output("echo Hello World!",
stderr=subprocess.STDOUT,
shell=True))
Output:
# ./ex.py
b'Hello World!\n'
Code:
#!/usr/bin/python3
import subprocess
print(subprocess.check_output("gecho Hello World!",
stderr=subprocess.STDOUT,
shell=True))
Output:
# ./ex.py
Traceback (most recent call last):
File "./ex.py", line 6, in <module>
shell=True))
File "/usr/lib64/python3.3/subprocess.py", line 589, in check_output
raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command 'gecho Hello World!' returned non-zero exit status 127