簡體   English   中英

QProcess不適用於“ wget”

[英]QProcess does not work with “wget”

我正在嘗試執行這樣的命令:

wget --user=abc --ask-password https://xxxxx.com/file.zip

然后我必須提供密碼。

此代碼應該處理它:

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幾次,但是這次我無法管​​理它。 有什么建議嗎? 我嘗試了不同的方法和任何響應。 當然,我下載的文件沒有下載。


我再次檢查,文件被下載到/ home目錄,而不是應用程序目錄。 這樣就可以了,但是沒有輸出。

您以錯誤的方式將參數傳遞給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();
}

如果您只輸入:

checkFW.setProcessChannelMode(QProcess::MergedChannels);

之前:

 checkFW.start();

您將在stdout中獲得所有輸出,甚至是錯誤

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM