在 QProcess 中执行 shell 命令
Executing the shell command in QProcess.Piping the input
我正在尝试管道命令并执行它,但我无法弄清楚如何管道它。 我正在尝试使用 shell 命令一次复制多个文件
对于 %I(源(复制 %I(目标(
QString files = "for %I in (source) do copy %I (destination)"
QProcess copy ;
copy.start(files);
我必须实现管道才能做到这一点。 例如。
QProcess sh;
sh.start("sh", QStringList() << "-c" << "ifconfig | grep inet");
sh.waitForFinished();
QByteArray output = sh.readAll();
sh.close();
如何为复制过程实现管道?
试试这个例子:
QProcess sh;
sh.start( "sh", { "-c", "ifconfig | grep inet" } );
if ( !sh.waitForFinished( -1 ) )
{
qDebug() << "Error:" << sh.readAllStandardError();
return -1;
}
const auto output = sh.readAllStandardOutput();
// ...
waitForFinished()
应该在阻止模式下调用,并且必须检查它是否成功。
相关文章:
- 使用提升过程获取 shell 命令的标准输出
- 如何在 Linux 下执行 shell 命令 unsing QProcess?
- 在 c++ 中从执行的 shell 命令获取返回状态的安全方法是什么?
- 在 QProcess 中执行 shell 命令
- 在结束运行之前获取 c++ 中的 shell 命令输出
- 如何在 Linux 中同时运行多个 shell 命令
- 如何在QT中使用pro文件在重新编译时执行shell命令?
- 如何将Mongo Shell命令转换为Mongocxx语法
- 使用 exec 在 c++ 中执行 shell 命令
- 使用qmake执行shell命令
- 在 pthread 中运行 shell 命令的良好和优化方法是什么?
- C++使用 shell 命令 WINDOWS 的输出定义宏 /D
- 在C++中执行shell命令时强制环境bash
- 从 shell 命令 Linux 读取值
- 在 c++ 中执行 Linux shell 命令,同时隐藏其输出
- 来自C 代码的Shell命令
- 用一些符号分隔shell命令
- 使用 execvp() 执行 shell 命令
- 有没有C++方法来调用 linux shell 命令
- 重复调用 shell 命令,通过管道捕获标准输出