polandeer
polandeer

Reputation: 396

How do I get the output of a command run by QProcess in PySide?

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.

Upvotes: 5

Views: 2925

Answers (2)

polandeer
polandeer

Reputation: 396

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

Upvotes: 3

ScarCode
ScarCode

Reputation: 3094

 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.

Upvotes: 2

Related Questions