subprocess.call()的返回值是多少? [英] What is the return value of subprocess.call()?

查看:3072
本文介绍了subprocess.call()的返回值是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定subprocess.call()的返回值是什么意思.

I am not sure what the return value of subprocess.call() means.

  • 我可以安全地假设一个零值将始终意味着该命令成功执行了吗?

  • Can I safely assume a zero value will always mean that the command executed successfully?

返回值等于shell命令的退出状态吗?

Is the return value equivalent to the exit staus of a shell command?

例如,下面的代码几乎可以在Linux上的任何命令上正常工作吗?

For example, will the following piece of code work for virtually any command on Linux?

 cmd = "foo.txt > bar.txt"
 ret = subprocess.call(cmd, shell=True)
 if ret != 0:
     if ret < 0:
         print "Killed by signal", -ret
     else:
         print "Command failed with return code", ret
 else:
     print "SUCCESS!!"

请赐教我:-)

推荐答案

是的,Subprocess.call返回实际过程返回代码".

Yes, Subprocess.call returns "actual process return code".

您可以查看 Subprocess.call Subprocess.Popen.returncode

这篇关于subprocess.call()的返回值是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆