使用子进程check_output获取输出

时间:2016-12-02 08:20:08

标签: python subprocess

我有这个exe文件“dexpt.exe”,它返回一个值,但下面的代码返回空白。可以提供任何帮助吗?

感谢 jayk

 #!/usr/bin/env python
import subprocess
import ctypes
tm=subprocess.check_output(['dexpt.exe'])
msgbox = ctypes.windll.user32.MessageBoxA
mbx= msgbox(None,tm, 'Title', 0)
print mbx

1 个答案:

答案 0 :(得分:0)

这是如何获得输出和错误,如果有一些但使用Popen。这个程序调用python脚本并返回error如果有的话(你可以很容易地修改它以返回outputdecode方法会将bytestring转换为string

def call_func():
    comand = "python test.py"
    proc = subprocess.Popen(comand.split(), shell=False,stdout= subprocess.PIPE,  stderr= subprocess.PIPE)
    if proc.wait() != 0:
        output, err = proc.communicate()
        return err.decode()
    return True
相关问题