Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess ssh call not see the output but is ok on linux terminal
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gfxx
    wrote on 24 Mar 2017, 11:02 last edited by
    #1

    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

    bkt

    J 1 Reply Last reply 24 Mar 2017, 11:07
    0
    • G gfxx
      24 Mar 2017, 11:02

      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

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 24 Mar 2017, 11:07 last edited by
      #2

      @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;");
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • G Offline
        G Offline
        gfxx
        wrote on 24 Mar 2017, 11:14 last edited by
        #3

        sorry not work

        regards
        giorgio

        bkt

        1 Reply Last reply
        0
        • V Offline
          V Offline
          VRonin
          wrote on 24 Mar 2017, 12:01 last edited by VRonin
          #4

          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");
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          3
          • G Offline
            G Offline
            gfxx
            wrote on 24 Mar 2017, 12:31 last edited by gfxx
            #5

            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

            bkt

            G 1 Reply Last reply 24 Mar 2017, 12:46
            0
            • G gfxx
              24 Mar 2017, 12:31

              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

              G Offline
              G Offline
              gfxx
              wrote on 24 Mar 2017, 12:46 last edited by gfxx
              #6

              @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

              bkt

              1 Reply Last reply
              0

              1/6

              24 Mar 2017, 11:02

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved