How to get the result of the QProcess command in PySide?

I would like to know how I can capture the output of a command launched by QProcess in PySide so that it can be displayed.

+5
source share
2 answers

I ended up using this:

  # Create runner
  self.runner = QProcess(self)
  # Make sure newInfo gets all output
  self.runner.readyReadStandardError.connect(self.newErrInfo)
  # Run the command
  self.runner.start(command)
  # Once it started set message to Converting
  self.parentWidget().statusBar().showMessage("Converting.")

Then in the class:

def newErrInfo(self):
  newString = str(self.runner.readAllStandardError())
  print(newString, end=" ")

readAllStandardOutput () also works for stdout

+1
source
 QProcess qp;
 qp.start("Yourcode");
 qp.waitForFinished();
 qDebug() << "qp:" << qp.readAll();

You can use functions such as canReadLine () , readiness () , waitforreadyread (), and waitforbyteswritten () to read live .

Use these functions in the signal slot mechanism to record real-time data.

+1
source

All Articles