Issue
When I use pyqt to run a program I cannot get the output correctly every time. Here is an example:
from PyQt4 import QtCore, QtGui
import sys
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QWidget.__init__(self)
program = "ping"
self.process = QtCore.QProcess()
self.process.readyRead.connect(self.readoutput)
self.process.start(program)
def readoutput(self):
print str(self.process.readAll())
def main():
app = QtGui.QApplication(sys.argv)
ex = MainWindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
In this case, the output is the helper of the ping command, as I would expect. Although if I change the program variable to some other value it doesn't always work, for example if i do:
program = "pyinstaller"
it does not print the helper of pyinstaller as it happens in the console. How am I supposed to get the output in this case?
Solution
pyinstaller might be printing to stderr instead of stdout. You can cause QProcess.readAll() to return both outputs by calling (before self.process.start(program)
)
setProcessChannelMode(QProcess.MergedChannels)
Answered By - David Ching
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.