2017-11-20 5 views
0

では動作しません。QProcessは、私は、このようなコマンドを実行しようとしています「wgetの」

このコードは、それを処理する必要があります

connect(&checkFW, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput())); 
//QString command = "wget --user=abc--ask-password https://xxxxxxx.com"; 
//checkFW.start("sh",QStringList() << "-c" <<"cd ;"+command); 
checkFW.start("wget", QStringList() << "--user=abc" << "--ask-password"<< "https://xxxxxx.com/file.zip"); 
if (!checkFW.waitForStarted()){ 
    qDebug()<<"Could not start "; 
    return false; 
} 

QString cmd = "password\n"; 
checkFW.write(cmd.toLatin1()); 
checkFW.waitForFinished(5000); 
QByteArray result = checkFW.readAll(); 
QString mystr(result); 
qDebug()<<"output:"<< mystr; 

私はQProcessを数回使用したが、この時間は、私はそれを動作するように管理することはできません。いくつかの提案?私は別のメトトと何かの反応を試みた。もちろん、私がreqestedファイルはダウンロードされませんでした。


もう一度チェックして、ファイルはアプリケーションのディレクトリではなく/ homeディレクトリにダウンロードされました。だから、動作しますが、出力はありません。

+0

あなたは 'wget'がプロセスの標準入力からパスワードを読み込むと仮定しています。私はそうではないと思う。 'wget'はおそらく[' getpass'](https://linux.die.net/man/3/getpass)のようなものに委任してパスワードを取得します。これは '/ dev/tty'に明示的に' open'を実行し、標準入力ではなく読み出すことになります。 –

答えて

0

引数を間違った方法でQProcessに渡しています。

checkFW.start("wget", QStringList() << "--user=abc" << "--ask-password"<< "https://xxxxxx.com/file.zip"); 

ping(Windows)の例です。

#include <QCoreApplication> 
#include <QProcess> 
#include <QDebug> 

int main(int argc, char *argv[]) 
{ 
    QProcess proc; 
    QStringList args; 
    args << "google.com"; 
    args << "-n"; 
    args << "3"; 

    proc.start("ping", args); 
    proc.waitForFinished(); 
    qDebug() << proc.readAllStandardOutput(); 
} 
+0

申し訳ありませんが、それは原因ではありません。私は議論の順序を変えてもまだ応答はありません。 – RobertLT

関連する問題