Qt 使用 QProcess
执行命令行脚本,并通过 readAllStandardOutput
获取其输出。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| #include <QCoreApplication> #include <QProcess> #include <QDebug>
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv);
QProcess cmdProcess;
QString command = "your_cmd_command"; cmdProcess.start(command); cmdProcess.waitForFinished();
QByteArray output = cmdProcess.readAllStandardOutput();
QString outputStr = QString::fromLocal8Bit(output); qDebug() << outputStr;
return a.exec(); }
|