def run_cmd(self, cmd):
print cmd
status = os.system(cmd)
print 'Command ran with Status: %s' % status
if status:
s = 'Command Failed: Status: %s for %s' % (status, cmd)
print s
sys.exit(status)
else:
s = 'Command Success: %s' % cmd
return status
我使用这个函数从另一个脚本运行python脚本。在
例如:
^{pr2}$
现在,如果script_b.py失败,script_a.py将退出,状态为。在
没关系。在
案例2:command_to_exec = 'python script_a.py --options'
rum_cmd(command_to_exec)
本例是script_a.py,从自身运行“python script_a.py”。
在这种情况下,如果新生成的脚本_a.py失败,则外部脚本_a.py仍然是成功的,因为它无法捕获内部脚本_a.py的失败(因为系统出口(状态)
现在,我该如何处理这种情况?(如果内部脚本_a失败,外部脚本_a应退出)