[英]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()
,并且必须检查它是否成功。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.