Write a small shell script that does exactly what you want, then execute the shell script using QProcess. For example, to take your original example, I'd write a small shell script named /path/to/test.sh as follows:
#!/bin/sh
iwconfig 2>&1 | grep ESSID
exit $?
#!/bin/sh
iwconfig 2>&1 | grep ESSID
exit $?
To copy to clipboard, switch view to plain text mode
Then execute QProcess as follows:
process.start("/path/to/test.sh");
process.waitForFinished();
QString output
= process.
readAllStandardOutput();
qDebug() << output;
QString err
= process.
readAllStandardError();
qDebug() << err;
QProcess process;
process.start("/path/to/test.sh");
process.waitForFinished();
QString output = process.readAllStandardOutput();
qDebug() << output;
QString err = process.readAllStandardError();
qDebug() << err;
To copy to clipboard, switch view to plain text mode
Of course you should add error checking, but that's the general gist of what anda_skoa is saying for one of the options he listed... You could also use two QProcess's where stdout from the 1st is piped to the 2nd QProcess's stdin, etc. Several options here, choose what's easiest for you to implement.
Good luck.
Bookmarks