Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 700
polandeer Avatar asked May 18 '12 17:05

polandeer


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'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

like image 64
polandeer Avatar answered Oct 13 '22 09:10

polandeer


 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.

like image 24
ScarCode Avatar answered Oct 13 '22 09:10

ScarCode