1

I want to get the output of this command for example :

system("dir C:\");

or of :

QProcess::execute("cmd /c dir C:\");

How to do that ?

Thanks !

Random78952
  • 1,520
  • 4
  • 26
  • 36

2 Answers2

5
QProcess process;
process.start("cmd /c dir C:\\");
process.waitForFinished(-1);
QByteArray out = process.readAllStandardOutput();
Jerry
  • 143
  • 4
1

You can modify the standard output path to be a pipe which you read from, but it would be easier to use popen() instead of system().

Since you appear to be using Windows, you would use _popen().

#include <stdio.h>

....

FILE *fp = _popen("dir c:\", "r");
....
while (!feof(fp)) {
    ....
}
fclose(fp);
mah
  • 39,056
  • 9
  • 76
  • 93