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. How to use QProcess to start smbclient when the filename with space.
Forum Updated to NodeBB v4.3 + New Features

How to use QProcess to start smbclient when the filename with space.

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 1.5k 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.
  • LeonSuL LeonSu

    OS: Debian for raspberry pi 3

    I inputted the command
    smbclient //192.168.3.50/d -U username -W ereryone password -c “get \”\data\win\image\0125 6-2.PNG\” /home/pi/Temp/004.png"

    on the terminal and it goes well.

    But, it doesn't work when I using the QProecess in the following code

    QString order = “smbclient //192.168.3.50/d -U username -W ereryone password -c \“get \”\data\win\image\0125 6-2.PNG\” /home/pi/Temp/004.png\””

    QProcess *process = new QProcess(this);
    process->start(order);
    process->waitForStarted(); //return true
    process->waitForFinished(); //return true

    the error message showed the path just include \data\win\image\0125 and the other are lost.

    Someone can help me or give me some suggests.

    Thanks in advance.

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #2

    @LeonSu
    Your code does not show how you pass your order variable to your QProcess. Until we know what this, we cannot help.

    1 Reply Last reply
    0
    • LeonSuL LeonSu

      OS: Debian for raspberry pi 3

      I inputted the command
      smbclient //192.168.3.50/d -U username -W ereryone password -c “get \”\data\win\image\0125 6-2.PNG\” /home/pi/Temp/004.png"

      on the terminal and it goes well.

      But, it doesn't work when I using the QProecess in the following code

      QString order = “smbclient //192.168.3.50/d -U username -W ereryone password -c \“get \”\data\win\image\0125 6-2.PNG\” /home/pi/Temp/004.png\””

      QProcess *process = new QProcess(this);
      process->start(order);
      process->waitForStarted(); //return true
      process->waitForFinished(); //return true

      the error message showed the path just include \data\win\image\0125 and the other are lost.

      Someone can help me or give me some suggests.

      Thanks in advance.

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #3

      @LeonSu Definition of order is not correct

      QString order = "smbclient //192.168.3.50/d -U username -W ereryone password -c \"get \"\data\win\image\0125 6-2.PNG\" /home/pi/Temp/004.png\""
      

      becomes

      smbclient //192.168.3.50/d -U username -W ereryone password -c "get "\data\win\image\0125 6-2.PNG" /home/pi/Temp/004.png"
      

      Quoted string in order are :

      "get " 
      " /home/pi/Temp/004.png"
      

      This version should work better:

      QString order = "smbclient //192.168.3.50/d -U username -W ereryone password -c get \"\data\win\image\0125 6-2.PNG\" \"/home/pi/Temp/004.png\""
      
      JonBJ 1 Reply Last reply
      0
      • Gojir4G Gojir4

        @LeonSu Definition of order is not correct

        QString order = "smbclient //192.168.3.50/d -U username -W ereryone password -c \"get \"\data\win\image\0125 6-2.PNG\" /home/pi/Temp/004.png\""
        

        becomes

        smbclient //192.168.3.50/d -U username -W ereryone password -c "get "\data\win\image\0125 6-2.PNG" /home/pi/Temp/004.png"
        

        Quoted string in order are :

        "get " 
        " /home/pi/Temp/004.png"
        

        This version should work better:

        QString order = "smbclient //192.168.3.50/d -U username -W ereryone password -c get \"\data\win\image\0125 6-2.PNG\" \"/home/pi/Temp/004.png\""
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #4

        @Gojir4
        How is that going to work correctly, given that you & he have a literal C++ string with (unprotected) \s in it?

        Come to that,

        the error message showed the path just include \data\win\image\0125

        Lucky if that happened. Perhaps you're just fortunate on \d, \w, \i & \0125 not happening to correspond to any C chars....

        Gojir4G 1 Reply Last reply
        0
        • JonBJ JonB

          @Gojir4
          How is that going to work correctly, given that you & he have a literal C++ string with (unprotected) \s in it?

          Come to that,

          the error message showed the path just include \data\win\image\0125

          Lucky if that happened. Perhaps you're just fortunate on \d, \w, \i & \0125 not happening to correspond to any C chars....

          Gojir4G Offline
          Gojir4G Offline
          Gojir4
          wrote on last edited by
          #5

          @JonB Right, I missed that, sry.
          So, this way :

          QString order = "smbclient //192.168.3.50/d -U username -W ereryone password -c get \"/data/win/image/0125 6-2.PNG\" \"/home/pi/Temp/004.png\""
          
          JonBJ 1 Reply Last reply
          0
          • Gojir4G Gojir4

            @JonB Right, I missed that, sry.
            So, this way :

            QString order = "smbclient //192.168.3.50/d -U username -W ereryone password -c get \"/data/win/image/0125 6-2.PNG\" \"/home/pi/Temp/004.png\""
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #6

            @Gojir4 , @LeonSu

            Although the above solves the "backslash" issue by using "forward slashes" instead (assuming that is acceptable to smbclient, I don't know), from what I can see elsewhere about smbclient command-line it may well not work.

            From the examples I have seen everywhere, including what @LeonSu wrote worked on the command line, I believe smbclient -c requires the following command to be a single argument, and hence be quoted. @Gojir4 's suggestion is passing two arguments, so I presume will likely not be acceptable.

            For the particular paths you have, I believe you should try:

            QString order = "smbclient //192.168.3.50/d -U username -W ereryone password -c \"get \\\"/data/win/image/0125 6-2.PNG\\\" /home/pi/Temp/004.png\""
            

            or you could try one of

            QString order = "smbclient //192.168.3.50/d -U username -W ereryone password -c \"get '/data/win/image/0125 6-2.PNG' /home/pi/Temp/004.png\""
            
            QString order = "smbclient //192.168.3.50/d -U username -W ereryone password -c 'get \"/data/win/image/0125 6-2.PNG\" /home/pi/Temp/004.png'"
            

            Even then I am unsure about who does the unquoting, so that may not be right.

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #7

              You really should pass the arguments with QProcess::setArguments() and not directly to start() - so you can be sure the separate arguments are treated as separate.

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

              1 Reply Last reply
              2
              • LeonSuL Offline
                LeonSuL Offline
                LeonSu
                wrote on last edited by
                #8

                thanks everyone

                I try to simplify the problem. I put file "0125 6-2.PNG" into folder d and didn't set any save path.

                The following command is work okay on the terminal

                smbclient //192.168.3.50/d -U username -W ereryone password -c "get \"0125 6-2.PNG\""
                

                @Gojir4

                QString order = "smbclient //192.168.3.50/d -U username -W ereryone password -c get \"0125 6-2.PNG\" "
                

                the error message say: get <filename>[localname] <== it lost the file name

                and I continue to try more like following

                QString order =  "smbclient //192.168.3.50/d -U username -W ereryone password -c get '0125 6-2.PNG' "
                

                I got the same result.

                @JonB

                I try

                QString order =  "smbclient //192.168.3.50/d -U username -W ereryone password -c \"get \\\"0125 6-2.PNG\\\"\""
                
                QString order =  "smbclient //192.168.3.50/d -U username -W ereryone password -c \"get '0125 6-2.PNG'\""
                

                The error message is 「NT_STATUS_OBJECT_NAME_NOT_FOUND onening remote file \0125」 for the above two case
                and

                QString order =  "smbclient //192.168.3.50/d -U username -W ereryone password -c 'get \"0125 6-2.PNG\"'"
                

                the error message is 「get <filename>[localname]」

                I base on your method to try following code

                QString order = "smbclient //192.168.3.50/d -U username -W ereryone password -c 'get '0125 6-2.PNG''"
                

                The error message is display 「'get: command not found」

                @Christian-Ehrlicher

                QString prog = "smbclient";
                QStringList arguments;

                arguments << "//192.168.3.50/d" << "-U" << "username" << "-W" << "workgroup" << "password" << "-c" << "\"get  0125 6-2.PNG\"";
                

                process->start(prog, arguments);
                the error message is 「get 0125 6-2.PNG: command not found」

                and I continue try the following code

                arguments << "//192.168.3.50/d" << "-U" << "username" << "-W" << "workgroup" << "password" << "-c" << " \"get  \"0125 6-2.PNG\"\"";
                

                the error message is 「get 0125: command not found」

                arguments << "//192.168.3.50/d" << "-U" << "username" << "-W" << "workgroup" << "password" << "-c" << "\"get  '0125 6-2.PNG'\"";
                

                the error message is 「get '0125 6-2.PNG': command not found」

                and

                arguments << "//192.168.3.50/d" << "-U" << "username" << "-W" << "workgroup" << "password" << "-c" << "\"get" <<  "\"0125 6-2.PNG\"" <<"\"";
                

                the error message is 「get <filename>[localname]」

                I guess the method (QProcess::setArguments()) is very close answer.

                Is anyone have idea?

                thanks again.

                1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by Christian Ehrlicher
                  #9

                  @LeonSu said in How to use QProcess to start smbclient when the filename with space.:

                  get \"0125 6-2.PNG\"

                  Since this is one argument, why don't you pass it to setArguments as one argument?

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

                  1 Reply Last reply
                  0
                  • LeonSuL Offline
                    LeonSuL Offline
                    LeonSu
                    wrote on last edited by
                    #10

                    thanks Christian-Ehrlicher
                    thanks everyone

                    the final code is following

                    QProcess *process = new QProcess(this);
                    
                    QString prog = "smbclient";
                    QStringList arguments;
                    
                    arguments << "//192.168.3.50/d" << "-U" << "username" << "-W" << "workgroup" << "password" << "-c" << "get \"0125 6-2.PNG\"";
                    
                    process->start(prog, arguments);
                    process->waitForStarted(); 
                    process->waitForFinished();
                    

                    thanks again;

                    @Christian-Ehrlicher
                    I don't know what different between using setArguments and without using setArguments.
                    The description from Qt documents is
                    「Set the arguments to pass to the called program when starting the process. This function must be called before start().」

                    In this case, I try to add the order(process->setArguments(arguments)), and the result is the same with above code.

                    QProcess *process = new QProcess(this);
                    
                    QString prog = "smbclient";
                    QStringList arguments;
                    
                    arguments << "//192.168.3.50/d" << "-U" << "username" << "-W" << "workgroup" << "password" << "-c" << "get \"0125 6-2.PNG\"";
                    
                    process->setArguments(arguments);
                    process->start(prog, arguments);
                    process->waitForStarted(); 
                    process->waitForFinished();
                    

                    Could you please show me some example.
                    thank you.

                    1 Reply Last reply
                    1
                    • Christian EhrlicherC Online
                      Christian EhrlicherC Online
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      setArguments(arguments) + start(cmt) and start(cmd, arguments) is exactly the same. I refered to your first try with start(cmd_with_args). In this case Qt must guess what a single argument is (and fails in your case because there are spaces inbetween which must be in one argument), therefore it is much better to not rely on this logic here to avoid this kind of confusion.

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

                      1 Reply Last reply
                      3

                      • Login

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