Reputation: 605
I am trying to execute command lines in a pyqt application, here is what I am doing so far:
stdouterr = os.popen4(cmd)[1].read()
simple, and for the most part it does work, but when I open up a text file for example, the pyqt programs stops until the text file is closed. Is there a way I can have something like that open and not stop my application.
Edit:
Okay I almost figured it out. I am currently doing this:
Popen(cmd, shell=True,
stdin=None, stdout=None, stderr=None, close_fds=True)
which does want I want it to, but is there a way to read stdout and stderr after the process is done running?
Upvotes: 2
Views: 3156
Reputation: 21
#my pyqt knowledge is not the best but this works for me... didn't use your example. hope you get it still.
from PyQt5.QtCore import QProcess
process = QProcess()
process.start("yourcommand")
process.waitForStarted()
process.waitForFinished()
process.readAll()
process.close()
'''
from PyQt5.QtCore import QProcess
process = QProcess()
process.start('driverquery')
process.waitForStarted()
process.waitForFinished():
process.waitForReadyRead()
tasklist = process.readAll()
process.close()
tasklist = str(tasklist).strip().split("\\r\\n")
print(tasklist)
'''
Upvotes: 2
Reputation: 7324
You can read from stdout
and stderr
like so:
process = subprocess.Popen(cmd, shell=True, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
stdout, stderr = process.communicate()
print stdout
print stderr
Upvotes: 0