我的部分代码:
import subprocess
import logging
logging.basicConfig(filename='daily_backup_run.log', level=logging.DEBUG)
try:
git_command = subprocess.Popen("git status", shell="true")
git_status_output = git_command.stdout.readline()
except subprocess.CalledProcessError, e:
git_status_output = e.output
logging.debug(' Output of git status: ' + git_status_output)
exit()
当我尝试运行它时,我的输出是:
[~/experiment_folder]# python git.py
Traceback (most recent call last):
File "git.py", line 35, in ?
except subprocess.CalledProcessError, e:
AttributeError: 'module' object has no attribute 'CalledProcessError'
fatal: Not a git repository (or any of the parent directories): .git
目前我并不关心 Python 错误,但我需要git 发送的所有输出进入daily_backup_run.log
- 甚至是fatal: Not a repo
错误。我如何确保这一点?