Can't get stdout/stderr from (Python) subprocess.check_output()
问题 I'm trying to get the message from a git add command, to print to a log file later on. import subprocess import os filename = 'test.txt' # Add changes add_cmd = """git add "%s" """ % filename os.system(add_cmd) a = subprocess.check_output(add_cmd, shell=True, stderr=subprocess.STDOUT) The os.system() call shows in screen: fatal: Not a git repository (or any of the parent directories): .git which is correct, since this folder is not a git repo. But the subprocess.check_output() call fails with