Ich versuche, die Nachricht von einem git add
Befehl zu erhalten, um später in eine Protokolldatei zu drucken.Kann stdout/stderr nicht von (Python) subprocess.check_output()
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)
Der os.system()
Aufruf zeigt in Bildschirm:
fatal: Not a git repository (or any of the parent directories): .git
, die korrekt ist, da dieser Ordner kein git
Repo ist.
Aber der subprocess.check_output()
Aufruf schlägt fehl mit:
File "test.py", line 11, in <module>
a = subprocess.check_output(add_cmd, shell=True, stderr=subprocess.STDOUT)
File "/usr/lib/python2.7/subprocess.py", line 573, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command 'git add "test.txt" ' returned non-zero exit status 128
Warum bin ich die Fehlermeldung zu fangen mit subprocess.check_output()
nicht in der Lage?