I am using Python 3.6.9 to call the following bash script:
run_cmds.sh:
ls dir_doesnt_exist | tee log Here is the Python code:
import subprocess from subprocess import PIPE cmd = subprocess.run(['bash','run_cmds.sh'], stdout=PIPE, stderr=PIPE) print(cmd.stderr.decode()) print("The returned code is:", cmd.returncode) Running the Python code, I get the following:
ls: cannot access 'dir_doesnt_exist': No such file or directory The returned code is: 0 As you can see, subprocess captures the standard error output but returncode is 0.
What is wrong with my Python script?
I appreciate any help.