我想使它從「check_call()」輸出「stdout」和「stderr」發送到Syslog。這可能嗎?打印功能輸出到系統日誌?
代碼:
def command(cmd, err=None, ifexit=False):
try:
check_call(shlex.split(cmd), stdout=null, stderr=null)
except CalledProcessError:
if err != None:
print err
if ifexit == True:
exit(1)
好的,但我怎麼讓Popen告訴我,如果命令執行成功? – Soviero
@Kevin只需檢查['process.returncode'](http://docs.python.org/library/subprocess.html?highlight=subprocess#subprocess.Popen.returncode)值或使用'process.wait() '方法。我已經更新了我的答案,等待命令完成並檢查它是否成功。 – MatToufoutu