开发者

No output from QProcess

开发者 https://www.devze.com 2022-12-13 19:00 出处:网络
Why does the following print a blank line instead of \'Hell开发者_运维技巧o QProcess\'? import sys

Why does the following print a blank line instead of 'Hell开发者_运维技巧o QProcess'?

import sys

from PyQt4 import QtGui, QtCore

proc = QtCore.QProcess()
proc.start("echo 'Hello QProcess'")
proc.waitForFinished()
result = proc.readAll()
print result
proc.close()

I'm on Windows XP, btw.


Because there's no program called "echo".

If you wanted to run this through the shell then you should have used "cmd /C echo Hello QProcess".

Your program also has no error checking. If you'd checked for errors properly the mistake would have been easier to spot.


You should provide system environment to your proc.

proc.setEnvironment(QProcess::systemEnvironment());

echo is exceptional command in Windows that does not have executable.

0

精彩评论

暂无评论...
验证码 换一张
取 消