0

I am trying to execute command like this:

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

then I have to deliver password.

This code should handle it:

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;

I used QProcess several times but this time I can't manage to work it. Some suggestions? I tried different methotds and any response. Of course the file I reqested was not downloaded.


I checked again and file was download to /home directory, not app's directory. So it works , but there is no output.

RobertLT
  • 41
  • 6
  • You're assuming `wget` will read the password from the process's standard input. I suspect that isn't the case. `wget` probably delegates to something like [`getpass`](https://linux.die.net/man/3/getpass) to fetch the password. That will, in turn, perform an explicit `open` on `/dev/tty` and read from that rather than the standard input. – G.M. Nov 21 '17 at 17:58

2 Answers2

0

You are passing arguments to the QProcess in a wrong way.

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

Here is example with 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

If you just put:

checkFW.setProcessChannelMode(QProcess::MergedChannels);

before:

 checkFW.start();

You will get all the output in stdout even the errors

CodeM
  • 1