Skip to content Skip to sidebar Skip to footer

Printing Qprocess Stdout Only If It Contains A Substring

A PyQt4 app runs ping in a QProcess. A QTextEdit named self.output will output everything from ping. A second QTextEdit named self.summary will only output the line if it contains

Solution 1:

One problem that you could have is that each output of QProcess could have several lines, ie contain "\n", to not have that problem we separate it, and then we do the search:

for line in processStdout.split("\n"):
    if"TTL"in line:
        cursorSummary.insertText(line+"\n")

In your initial code you are getting each character with the for loop, which is generating the error.

enter image description here

Note: In linux I have to filter by the word ttl. In addition to changing the QProcess to: self.process.start('ping', ['-c', '3', '127.0.0.1'])

Post a Comment for "Printing Qprocess Stdout Only If It Contains A Substring"