5

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

polandeer
  • 396
  • 4
  • 16

2 Answers2

3

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's started set message to Converting
  self.parentWidget().statusBar().showMessage("Converting.")

Then later in the class:

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

readAllStandardOutput() also works for stdout

polandeer
  • 396
  • 4
  • 16
2
 QProcess qp;
 qp.start("Yourcode");
 qp.waitForFinished();
 qDebug() << "qp:" << qp.readAll();

For Reading live you can use functions like canReadLine(),readyread(),waitforreadyread() and waitforbyteswritten().

Use these functions in signal-slot mechanism for capturing data live.

ScarCode
  • 3,074
  • 3
  • 19
  • 32