久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 QProcess 管道(或命令鏈)

Piping (or command chaining) with QProcess(使用 QProcess 管道(或命令鏈))
本文介紹了使用 QProcess 管道(或命令鏈)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 Qt 并對其進行 bash,需要執(zhí)行如下操作:

I'm using Qt and bash over it, need to execute something like:

bash: cat file | grep string

在 Qt 中:

QString cmd = "cat file | grep string";
QProcess *process = new QProcess;
process->start(cmd);
process->waitForBytesWritten();
process->waitForFinished();
qDebug() << process->readAll();

問題出在管道(|")中,進程沒有返回任何內(nèi)容.如果沒有(|"),比如

The problem is in pipe ("|"), and process returs nothing. If there is no ("|"), like

"cat file" 

一切正常.我試過了.喜歡

everything is ok. I tried smth. like

"cat file \| grep string", 
"cat file | grep string" 

但結果是一樣的.如果我復制命令并在 bash 中運行它,一切正常.

but result is the same. If I copy the command and run it in bash everything is ok.

QString::toAscii().data()

和其他轉(zhuǎn)換也有不好的結果.

and other transforms also have bad result.

推薦答案

問題是您不能使用 QProcess 運行系統(tǒng)命令,而只能運行單個進程.因此,解決方法是將您的命令作為參數(shù)傳遞給 bash:

The problem is you cannot run a system command with QProcess, but only a single process. So the workaround will be to pass your command as an argument to bash:

process.start("bash", QStringList() << "-c" << "cat file | grep string");

這篇關于使用 QProcess 管道(或命令鏈)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 成人欧美一区二区三区白人 | 91免费视频| 秋霞电影一区二区三区 | 欧美午夜精品久久久久免费视 | 久久久www | 精品免费国产 | 日本三级电影在线观看视频 | 免费视频一区二区三区在线观看 | 久久久久久久久久久久91 | 91看片在线观看 | 亚洲国产在 | 中文字幕成人 | 精品欧美激情在线观看 | 爱爱爱av| 久久婷婷国产香蕉 | 国产91久久久久蜜臀青青天草二 | 国产不卡视频在线 | 国产乱码精品一区二区三区五月婷 | 99视频在线| 在线色网| 欧美一区二区大片 | 成人妇女免费播放久久久 | 久久精品99 | 99久久精品国产毛片 | 99爱在线视频 | 欧美爱爱视频网站 | 操久久| jdav视频在线观看免费 | 在线国产一区 | 久久大| 久久久91精品国产一区二区精品 | 91精品观看| 国产粉嫩尤物极品99综合精品 | 国产精品网址 | 日日骚网 | 日日操夜夜操视频 | 妹子干综合 | 久久新| 久久精品免费 | 亚洲精品一区二区在线观看 | 操操日|