私のコードの一部:
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
ます。どうすればこれを保証できますか?