获取用Qt和C ++编写的exe的输出

时间:2016-04-10 19:00:51

标签: python qt

我正在编写一个python脚本,我正在编写调用exe文件(subrocess.Popen)。我正在将stdout和stderr重定向到PIPE,但我无法读取(subprocess.Popen.stdout.readline())任何输出。

我确实尝试在windows cli中运行exec文件并重定向stdout和stderr ......但没有任何反应。所以我认为这个Qt应用程序中没有stdout和stderr。

有什么方法可以获取在屏幕上打印此exe的数据(通过应用程序是photivo.exe的方式)?

2 个答案:

答案 0 :(得分:0)

  

警告:使用communic()而不是.stdin.write,.stdout.read或.stderr.read来避免由于任何其他OS管道缓冲区填满并阻止子进程而导致的死锁过程

https://docs.python.org/3/library/subprocess.html#subprocess.Popen.stderr

这意味着尝试这样的事情

process = subrocess.Popen(...)
stdout, stderr = process.communicate()
print(stdout)
print(stderr)

答案 1 :(得分:0)

来自http://doc.qt.io/qt-5/debug.html

  

使用Windows,如果是控制台应用程序,则将文本发送到控制台;否则,会将其发送到调试器

Windows上有一个特殊的调试通道(WinAPI函数OutputDebugString)。另请参阅How does Qt5 redirect qDebug() statements to the Qt Creator 2.6 console

现在有可能photivo.exe使用普通的qDebug()来产生输出,从而写入调试通道。您可以尝试使用the tool DebugView验证这一点。

在这种情况下,您必须找到一种方法从Python读取调试通道或fork photivo.exe并使其使用STDOUT / STDERR而不是qDebug()。