views:

69

answers:

2

I thought I was going to get the output from a QProcess using the following code:

// Start the process
process.start(tr("php-cgi www/test.php"),QIODevice::ReadWrite);

// Wait for it to start
if(!process.waitForStarted())
    return 0;

// Continue reading the data until EOF reached
QByteArray data;

while(process.waitForReadyRead())
    data.append(process.readAll());

// Output the data
qDebug(data.data());
qDebug("Done!");

What I am expecting is to see the output from the program printed to the debug console, but all I see is:

Done!

I know that:

  • The program is started fine, because the message at the end is printed.
  • The program does print output because running the exact same command in the terminal produces a long string of text as expected.

What am I doing wrong here?

+1  A: 

befor starting your process call: process.setProcessChannelMode(QProcess::MergedChannels);. It will cause printing everything (even stderr output) to stdout output.

Kamil Klimek
+1  A: 

Have a look at the accepted answer to this similar question : http://stackoverflow.com/questions/2148185/run-linux-command-line-commands-from-qt4/2148360#2148360

Fred
Solution in this question also makes sense, but it doesn't keep order of messages
Kamil Klimek