QProcess ssh call not see the output but is ok on linux terminal

  • hi,

    a little problem ... I use these string in terminal linux:

    ssh b@ /home/b/file.py  pippo.txt

    an these retun me the position on remote pc of file pippo.txt ... it's all right in linux terminal, but when i use QProcess the output is blank row ...

    I use an other QProcess with "scp" command to copy pippo.txt on remote pc and it work fine. After any start there is a close after these example:

        QString PGRnameload;
        ConnectionLoad = new QProcess();
        ConnectionLoad->start("/bin/sh", QStringList() << "-c" << " ssh b@ /home/b/file.py pippo.txt ;"); /*if try to leave ';' is the same*/
        PGRnameload = ConnectionLoad->readAllStandardOutput().simplified();

    appreciate any suggst.


  • Moderators

    @gfxx Should be

    ConnectionLoad->start("/bin/sh", QStringList() << "-c" << "ssh" << "b@"<< "/home/b/file.py" << "pippo.txt;");

    Also you do not need to use sh:

    ConnectionLoad->start("ssh", QStringList() << "b@"<< "/home/b/file.py" << "pippo.txt;");

  • sorry not work


  • You are using the API wrong

    QString* PGRnameload=new QString;
        QProcess* ConnectionLoad = new QProcess(this); // local variable works
    connect(ConnectionLoad,&QProcess::readyReadStandardOutput,ConnectionLoad,[PGRnameload,ConnectionLoad]()->void{ PGRnameload->append(QString::fromLatin1(ConnectionLoad->readAllStandardOutput()));});
    connect(ConnectionLoad,&QProcess::readyReadStandardError,ConnectionLoad,[PGRnameload,ConnectionLoad]()->void{ PGRnameload->append(QString::fromLatin1(ConnectionLoad->readAllStandardError()));});
    connect(ConnectionLoad, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),ConnectionLoad,&QProcess::deleteLater);
    connect(ConnectionLoad, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),this,
        [PGRnameload,this](){ ui->ErrorString->append(*PGRnameload); ui->m1lineEdit->setText(*PGRnameload); delete PGRnameload; });
        ConnectionLoad->start("ssh", QStringList() << "b@"<< "/home/b/file.py" << "pippo.txt");

  • Hi VRonin ... why you use all these lambda functions?


    QProcess* ConnectionLoad

    I declare it private.

    Any how not undestand your code and it return me a lot of error ... surely the code itself works well it's just that I do not understand it so I do not understand how to fix the errors.
    For example why a static_cast to qprocess??

    and where is my error in my original code? TANKS A LOT

    mmm ... the problem is the time when I capture the output?

  • @VRonin ... hoops it works ... and now I study better the lambda usage in these way.

    then use these:

    ConnectionLoad->start("ssh", QStringList() << "b@"<< "/home/b/file.py" << "pippo.txt");

    or these:

    QString Stringload = " ssh b@ /home/b/file.py pippo.txt";
    ConnectionLoad->start("/bin/sh", QStringList() << "-c" << QString(Stringload ));

    is the same


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.