我一直在使用一个简短的python脚本来执行bash命令。该程序在大约一个月的时间内运行良好。最近,我尝试运行脚本,向它传递以下命令:
my_launcher.py -c /path/to/config/file.json(顺便说一句,当在终端中输入命令时,我不会导致任何错误,并且运行正常),并且我得到以下消息:
RuntimeError: Command '['bash', '-c', 'my_launcher.py -c /path/to/config/file.json']' returns non-zero exit status (code5)在Google上查找后,我找到了返回码0、1和2的定义,但没有找到返回码5的定义。这是什么意思?如何解决呢?等。
以下是导致错误的python代码:
try :
#check_output produces byte string
#raises exception if command returns a non-zero exit status (error occurs during processing of command)
string_of_text_rc = subprocess.check_output(['bash', '-c', bashCommand])
except subprocess.CalledProcessError as e:
raise RuntimeError("Command '{}' returns non-zero exit status (code{})".format(e.cmd, e.returncode))删除try/except时,taceback如下所示:
Traceback (most recent call last):
File "bash_cmd.py", line 27, in <module>
run_cmd('my_launcher.py -c /path/to/config/file.json')
File "bash_cmd.py", line 17, in run_cmd
string_of_text_rc = subprocess.check_output(['bash', '-c', bashCommand])
File "/usr/lib64/python2.7/subprocess.py", line 575, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['bash', '-c', 'my_launcher.py -c /path/to/config/file.json']' returned non-zero exit status 5**编辑:将正确的输出包含到e.output中。这意味着该命令已运行并返回正确的输出。我真的不知道为什么我会得到这个错误代码。
https://stackoverflow.com/questions/51192313
复制相似问题