Q "wget"不适用于

QProcess does not work with "wget"

本文关键字:适用于 不适用 wget      更新时间:2023-10-16

我正在尝试执行这样的命令:

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 = "passwordn";
checkFW.write(cmd.toLatin1());
checkFW.waitForFinished(5000);
QByteArray result = checkFW.readAll();
QString mystr(result);
qDebug()<<"output:"<< mystr;

多次使用QProcess,但这次我无法工作。一些建议?我尝试了不同的methotds和任何反应。当然,我要求的文件没有下载。


我再次检查,文件已下载到/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();

您将在标准输出中获得所有输出,甚至是错误

相关文章: