2
我試圖從git add
命令中獲取消息,以便日後打印到日誌文件。無法從(Python)subprocess.check_output()獲取stdout/stderr()
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)
的os.system()
呼叫顯示屏幕:
fatal: Not a git repository (or any of the parent directories): .git
這是正確的,因爲這個文件夾是不是一個git
回購。
但subprocess.check_output()
調用失敗:
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
爲什麼我不能夠捕獲錯誤消息subprocess.check_output()
?