How to redirect Python console output to QTextBox

I am working on a GUI to recompile the Linux kernel. To do this, I need to implement 4-5 Linux commands from Python. I use Qt as a GUI designer. I successfully executed the commands with a call os.system(). But the output is on the console. The real problem - the output of the command is a list that requires continuous printing lasting 20-25 minutes. How can we pass this console output to a text box developed in Qt. Can someone help me implement an operation setSource()in Qt using the source as real-time outputs.

+3
source share
3 answers
self.process = QProcess()
self.connect(self.process, SIGNAL("readyReadStdout()"), self.readOutput)
self.connect(self.process, SIGNAL("readyReadStderr()"), self.readErrors)
tarsourcepath="sudo tar xvpf "+ self.path1
self.process.setArguments(QStringList.split(" ",tarsourcepath))
self.process.start()



def readOutput(self):

    self.textBrowser2.append(QString(self.process.readStdout()))
    if self.process.isRunning()==False:
        self.textBrowser2.append("\n Completed Successfully")




def readErrors(self):
    self.textBrowser2.append("error: " + QString(self.process.readLineStderr()))

. .

+5

wxPython, http://diotavelli.net/PyQtWiki/Capturing_Output_from_a_Process , ?

:

: , , .

( ): QProcess, , . stdout stderr .

...

+1

. , ( GUI , ).

, :

os.chdir("/usr/src/linux-2.6.34")

p = os.popen("make", "r")
try:
    while True:
        line = p.readline()
        if not line:
            break

        # Replace this with a GUI update event (don't know anything about Qt, sorry)
        print line
finally:
    # Cf. http://docs.python.org/library/os.html#os.popen
    programReturnValue = p.close() or 0
0

Source: https://habr.com/ru/post/1746027/


All Articles