【发布时间】:2020-05-24 19:28:55
【问题描述】:
我有一个脚本正在执行 5 个不同的 shell 命令,我正在使用 subprocess.check_call() 来执行它们。问题是我似乎无法弄清楚如何正确捕获和分析返回码。
根据文档The CalledProcessError object will have the return code in the returncode attribute.,但我不明白如何访问它。如果我说
rc = subprocess.check_call("command that fails")
print(rc)
它告诉我
subprocess.CalledProcessError: 命令“失败的命令”返回非零退出状态 1
但我不知道如何仅捕获 1 的整数输出。
我想这一定是可行的?
【问题讨论】:
标签: python subprocess