ifconfig | grep 'inet'
is working when executed via terminal. But not via QProcess
My sample code is
QProcess p1;
p1.start("ifconfig | grep 'inet'");
p1.waitForFinished();
QString output(p1.readAllStandardOutput());
textEdit->setText(output);
Nothing is getting displayed on textedit.
but when I use just ifconfig in start of qprocess, output is getting displayed on textedit. Did I miss any trick to construct the command ifconfig | grep 'inet' , like use \' for ' and \| for |? for special characters? but I tried that as well:(
QProcess executes one single process. What you are trying to do is executing a shell command, not a process. The piping of commands is a feature of your shell.
There are three possible solutions:
Put the command you want to be executed as an argument to
shafter-c(“command”):Or you could write the commands as the standard input to
sh:Another approach which avoids
sh, is to launch two QProcesses and do the piping in your code: