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. Unable to run QProcess with sshpass in Windows
Forum Updated to NodeBB v4.3 + New Features

Unable to run QProcess with sshpass in Windows

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.1k Views 2 Watching
  • 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.
  • R Offline
    R Offline
    Ryna
    wrote on 26 May 2021, 18:19 last edited by
    #1

    Hi all,
    I am trying to copy a file over ssh by passing the password through sshpass in windows. Surprisingly each command works like date, time while using the same code but sshpass appears doesn't execute at all. Here is what my code looks like-

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    {
        myProcess = new QProcess(this);
        connect (myProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(slot_readStandardOutput()));
        connect (myProcess, SIGNAL(readyReadStandardError()), this, SLOT(slot_readStandardError()));
        connect (myProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slot_processFinished(int, QProcess::ExitStatus)));
        connect (myProcess, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(slot_processErrorOccured(QProcess::ProcessError)));
    
        myProcess->start("cmd.exe", QStringList() << "C:/cygwin64/bin/sshpass.exe -p password C:/cygwin64/bin/scp.exe -r pi@192.168.5.16:/home/pi/Test .", QIODevice::ReadOnly);
    }
    

    But execution of "C:/cygwin64/bin/sshpass.exe -p password C:/cygwin64/bin/scp.exe -r pi@192.168.5.16:/home/pi/Test ." works fine on command prompt. Any help is appreciated. Thanks

    1 Reply Last reply
    0
    • R Ryna
      26 May 2021, 18:37

      @Christian-Ehrlicher said in Unable to run QProcess with sshpass in Windows:

      This is for sure not correct since sshpass wants single arguments (at least I would guess so).

      sshpass asks for password which goes with -p, this is what its usage says -

      Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
      -f filename Take password to use from file
      -d number Use number as file descriptor for getting password
      -p password Provide password as argument (security unwise)
      -e Password is passed as env-var "SSHPASS"
      With no parameters - password will be taken from stdin

      -P prompt Which string should sshpass search for to detect a password prompt
      -v Be verbose about what you're doing
      -h Show help (this screen)
      -V Print version information
      At most one of -f, -d, -p or -e should be used

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 26 May 2021, 18:43 last edited by mrjj
      #4

      @Ryna
      Hi
      Do we need to run it via CMD ?

      why not like

      Process->start("C:/cygwin64/bin/sshpass.exe", QStringList() << "-p" << "password" << "C:/cygwin64/bin/scp.exe" << "-r"  << "pi@192.168.5.16:/home/pi/Test", QIODevice::ReadOnly);
      
      
      R 1 Reply Last reply 26 May 2021, 18:57
      1
      • C Online
        C Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 26 May 2021, 18:21 last edited by
        #2

        @Ryna said in Unable to run QProcess with sshpass in Windows:

        "C:/cygwin64/bin/sshpass.exe -p password C:/cygwin64/bin/scp.exe -r pi@192.168.5.16:/home/pi/Test ."

        This is for sure not correct since sshpass wants single arguments (at least I would guess so).

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        R 1 Reply Last reply 26 May 2021, 18:37
        1
        • C Christian Ehrlicher
          26 May 2021, 18:21

          @Ryna said in Unable to run QProcess with sshpass in Windows:

          "C:/cygwin64/bin/sshpass.exe -p password C:/cygwin64/bin/scp.exe -r pi@192.168.5.16:/home/pi/Test ."

          This is for sure not correct since sshpass wants single arguments (at least I would guess so).

          R Offline
          R Offline
          Ryna
          wrote on 26 May 2021, 18:37 last edited by
          #3

          @Christian-Ehrlicher said in Unable to run QProcess with sshpass in Windows:

          This is for sure not correct since sshpass wants single arguments (at least I would guess so).

          sshpass asks for password which goes with -p, this is what its usage says -

          Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
          -f filename Take password to use from file
          -d number Use number as file descriptor for getting password
          -p password Provide password as argument (security unwise)
          -e Password is passed as env-var "SSHPASS"
          With no parameters - password will be taken from stdin

          -P prompt Which string should sshpass search for to detect a password prompt
          -v Be verbose about what you're doing
          -h Show help (this screen)
          -V Print version information
          At most one of -f, -d, -p or -e should be used

          M C 2 Replies Last reply 26 May 2021, 18:43
          0
          • R Ryna
            26 May 2021, 18:37

            @Christian-Ehrlicher said in Unable to run QProcess with sshpass in Windows:

            This is for sure not correct since sshpass wants single arguments (at least I would guess so).

            sshpass asks for password which goes with -p, this is what its usage says -

            Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
            -f filename Take password to use from file
            -d number Use number as file descriptor for getting password
            -p password Provide password as argument (security unwise)
            -e Password is passed as env-var "SSHPASS"
            With no parameters - password will be taken from stdin

            -P prompt Which string should sshpass search for to detect a password prompt
            -v Be verbose about what you're doing
            -h Show help (this screen)
            -V Print version information
            At most one of -f, -d, -p or -e should be used

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 26 May 2021, 18:43 last edited by mrjj
            #4

            @Ryna
            Hi
            Do we need to run it via CMD ?

            why not like

            Process->start("C:/cygwin64/bin/sshpass.exe", QStringList() << "-p" << "password" << "C:/cygwin64/bin/scp.exe" << "-r"  << "pi@192.168.5.16:/home/pi/Test", QIODevice::ReadOnly);
            
            
            R 1 Reply Last reply 26 May 2021, 18:57
            1
            • R Ryna
              26 May 2021, 18:37

              @Christian-Ehrlicher said in Unable to run QProcess with sshpass in Windows:

              This is for sure not correct since sshpass wants single arguments (at least I would guess so).

              sshpass asks for password which goes with -p, this is what its usage says -

              Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
              -f filename Take password to use from file
              -d number Use number as file descriptor for getting password
              -p password Provide password as argument (security unwise)
              -e Password is passed as env-var "SSHPASS"
              With no parameters - password will be taken from stdin

              -P prompt Which string should sshpass search for to detect a password prompt
              -v Be verbose about what you're doing
              -h Show help (this screen)
              -V Print version information
              At most one of -f, -d, -p or -e should be used

              C Online
              C Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 26 May 2021, 18:46 last edited by
              #5

              @Ryna said in Unable to run QProcess with sshpass in Windows:

              sshpass asks for password which goes with -p, this is what its usage says -

              But it needs it as single arguments, not as one.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              R 1 Reply Last reply 26 May 2021, 19:02
              1
              • M mrjj
                26 May 2021, 18:43

                @Ryna
                Hi
                Do we need to run it via CMD ?

                why not like

                Process->start("C:/cygwin64/bin/sshpass.exe", QStringList() << "-p" << "password" << "C:/cygwin64/bin/scp.exe" << "-r"  << "pi@192.168.5.16:/home/pi/Test", QIODevice::ReadOnly);
                
                
                R Offline
                R Offline
                Ryna
                wrote on 26 May 2021, 18:57 last edited by Ryna
                #6

                @mrjj said in Unable to run QProcess with sshpass in Windows:

                C:/cygwin64/bin/sshpass.exe", QStringList() << "-p" << "password" << "C:/cygwin64/bin/scp.exe" << "-r" << "pi@192.168.5.16:/home/pi/Test", QIODevice::ReadOnly);

                I tried this and it worked. It was just copying it to different location. I can try to debug and figure that out.. Thank you so much.

                1 Reply Last reply
                0
                • C Christian Ehrlicher
                  26 May 2021, 18:46

                  @Ryna said in Unable to run QProcess with sshpass in Windows:

                  sshpass asks for password which goes with -p, this is what its usage says -

                  But it needs it as single arguments, not as one.

                  R Offline
                  R Offline
                  Ryna
                  wrote on 26 May 2021, 19:02 last edited by
                  #7

                  @Christian-Ehrlicher
                  I understood what you meant to say. This worked.. Thank you so much :)

                  1 Reply Last reply
                  1

                  1/7

                  26 May 2021, 18:19

                  • Login

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