2

Hi I am firing a detached process from Qt using QProcess. I want to read the console output of the process in a QString. Here is the code

#include <QCoreApplication>
#include <QProcess>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QProcess proc;
    proc.startDetached("C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe", 
                        QStringList() << "/c" << "c:\\Qt\\Qt5.3.0\\Tools\\QtCreator\\bin\\tryScript\\firstBatch.bat");


    proc.waitForFinished();
    qDebug() << proc.readAllStandardOutput();

    return a.exec();
}
Nejat
  • 31,784
  • 12
  • 106
  • 138
ishan3243
  • 1,870
  • 4
  • 30
  • 49

1 Answers1

2

QProcess::startDetached is not a member function, its a static function, so

proc.startDetached(...)

is equivalent to :

QProcess::startDetached(...)

Hence there's no state or output in your proc variable for the detached process. Use the start() method if you want to start the process as a subprocess of your application and read its output.

Nejat
  • 31,784
  • 12
  • 106
  • 138