代码
#include <iostream>
#include <QProcess>
int main(int argc, char *argv[])
{
QProcess process;
QStringList arguments;
// 构造参数
arguments << "/c" << "cd ./7-Zip" << "&& 7z.exe x -y ../compress/test.zip -o../decompress/";
// 启动进程
process.start(QString::fromLocal8Bit("cmd.exe"), arguments);
// 等待结束
while (process.waitForFinished() == false)
{
std::cout << "process timeout" << std::endl;
process.terminate();
break;
}
// 标准输出
std::cout << process.readAllStandardOutput().data() << std::endl;
// 状态码
std::cout << process.exitStatus() << std::endl;
// 退出码(状态码正常时退出码才有效)
std::cout << process.exitCode() << std::endl;
return 0;
}
7-Zip 22.01 (x86) : Copyright (c) 1999-2022 Igor Pavlov : 2022-07-15
Scanning the drive for archives:
1 file, 22673750 bytes (22 MiB)
Extracting archive: ..\compress\test.zip
--
Path = ..\compress\test.zip
Type = zip
Physical Size = 22673750
Everything is Ok
Folders: 7
Files: 52
Size: 60630282
Compressed: 22673750
0
0
7-Zip 22.01 (x86) : Copyright (c) 1999-2022 Igor Pavlov : 2022-07-15
Scanning the drive for archives:
0
2
参考
# 官方中文网站
https://sparanoid.com/lab/7z/
# 一个命令行同时执行多条命令
https://blog.youkuaiyun.com/Castlehe/article/details/113973285