0

This question is similar to this one. The difference is that the solution specified there doesn't work always.

Example 1

QProcess * process;
process = new QProcess();
process->start("/usr/bin/env");
process->waitForFinished(-1);

QString p_stdout = process->readAllStandardOutput();
qDebug() << p_stdout;

//output
HOME=/home
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/sbin:/usr/sbin
DISPLAY=:0.0
SHELL=/bin/sh
PWD=/home

Everything works, and the output is like typing /usr/sbin/env in the terminal.

Example 2

QProcess * process;
process = new QProcess();
process->start("/usr/sbin/iptables");
process->waitForFinished(-1);

QString p_stdout = process->readAllStandardOutput();
qDebug() << p_stdout;

//output
""

Same code, just a different command and no output. There is output when i type /usr/sbin/iptables in the terminal

iptables v1.4.16.3: no command specified Try `iptables -h' or 'iptables --help' for more information.

bit it doesn't appear in p_stdout. What is the catch with this solution?

Community
  • 1
  • 1
TheMeaningfulEngineer
  • 15,679
  • 27
  • 85
  • 143

0 Answers0