python - 如何在python中获取返回状态

标签 python python-2.7

我正在使用子进程调用从 python 脚本调用可执行文件。这些是我使用的以下代码:

try:
    p = subprocess.Popen([abc.exe], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()

except Exception as e:
    print str(e)

在 abc.exe 中,我在失败情况下返回 1,在成功情况下返回 0。但是我不知道如何在 python 脚本中检查返回值。

谢谢,

最佳答案

Popen.returncode包含进程终止时的返回码。您可以确保使用 Popen.wait .

关于python - 如何在python中获取返回状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18829118/

相关文章:

python - 在python中转换d-m-Y

python - 在我的脚本中获取 "TypeError: an integer is required"

python - 如何在 Windows 上安装 .egg Python 包(尝试使用 easy_install 不起作用)

python - 根据字符串中的第一个字符查找字符串列表中元素的第一次出现

python - pygame绘制函数

python - 如何加速 Django 管理页面?

python-2.7 - 快速实现单词的字符n-gram

python - 更新 panda 中的整个 Excel 行

python - 快速任意分布随机采样(逆变换采样)

python unittest 运行服务器和客户端并传递 raw_input