I need to force my c++ QT4 application to read results from a linux command. I am trying to use Qprocess but as soon as my command gets complicated it get messed somehow (just guessing) and does not work.
Here i try to make for yu a small example:
QProcess process;
command = "ls -l | grep a | sort";
qDebug() << "Execute command -> "+command;
process.start( command );
process.waitForFinished(-1);
QString processStdout = process.readAllStandardOutput();
QString processStderr = process.readAllStandardError();
qDebug() << "Std out -> "+processStdout;
qDebug() << "Std err -> "+processStderr;
this will print:
Execute command -> ls -l | grep a | sort
"Std out -> "
"Std err -> ls: |: No such file or directory
while would correctly print the file names if runed from the consol.
If i replace the comman with somethink simpler such command = "ls -l";
it work smoothless
The error is returned on standar error by the OS.
I guess thereforethat the Qstring used for the command gets manipolated somehow. Any idea about wht's happening?