【发布时间】:2017-11-20 22:18:22
【问题描述】:
我正在尝试执行这样的命令:
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 目录,而不是应用程序的目录。所以它可以工作,但是没有输出。
【问题讨论】:
-
您假设
wget将从进程的标准输入中读取密码。我怀疑情况并非如此。wget可能委托给getpass之类的东西来获取密码。反过来,这将在/dev/tty上执行显式open并从中读取而不是标准输入。