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@119.204.0.122 /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@119.204.0.122 /home/b/file.py pippo.txt ;"); /*if try to leave ';' is the same*/
        ConnectionLoad->waitForStarted(1500);
        ConnectionLoad->waitForFinished(1500);
        PGRnameload = ConnectionLoad->readAllStandardOutput().simplified();
        ui->ErrorString->append(PGRnameload);
        ui->m1lineEdit->setText(PGRnameload);
        ConnectionLoad->close();
    
    

    appreciate any suggst.

    regards
    giorgio


  • Moderators

    @gfxx Should be

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

    Also you do not need to use sh:

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


  • sorry not work

    regards
    giorgio



  • 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@119.204.0.122"<< "/home/b/file.py" << "pippo.txt");
    


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

    then:

    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?
    regards
    giorgio



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

    then use these:

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

    or these:

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

    is the same

    regards
    giorgio


Log in to reply
 

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