[英]How to get the output of system() command qt c++?
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 ! 谢谢 !
QProcess process;
process.start("cmd /c dir C:\\");
process.waitForFinished(-1);
QByteArray out = process.readAllStandardOutput();
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()
. 您可以将标准输出路径修改为您要读取的管道,但是使用
popen()
而不是system()
会更容易。
Since you appear to be using Windows, you would use _popen()
. 由于您似乎正在使用Windows,因此应使用
_popen()
。
#include <stdio.h>
....
FILE *fp = _popen("dir c:\", "r");
....
while (!feof(fp)) {
....
}
fclose(fp);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.