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. Weird behavior of QProcess and multiple qoutes
Forum Updated to NodeBB v4.3 + New Features

Weird behavior of QProcess and multiple qoutes

Scheduled Pinned Locked Moved Solved General and Desktop
36 Posts 7 Posters 6.5k 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.
  • M Offline
    M Offline
    Manta Ray
    wrote on last edited by
    #11

    Ahaaaa, Thanks you guys a lot!!!!!!
    I really appreciate you!!!!

    1 Reply Last reply
    1
    • G Offline
      G Offline
      Guanhong
      wrote on last edited by
      #12

      @Manta-Ray
      I met the same issue and it failed.
      Could you show me your codes or tell me what's wrong with my codes following, thanks

                  QString strSSID = "12345678"
                  QString program = "wpa_cli";
                  QStringList arguments;      
                  arguments << "-i" << "wlan0" << "set_network" << "0"<< "ssid" << "'\"" << strSSID << "\"'";  
                  QProcess prcsWlan4;
                  prcsWlan4.start(program, arguments);
                  prcsWlan4.waitForFinished(-1);  
                  QString strResult4 = prcsWlan4.readAllStandardOutput();
      

      the result strResult4 is FAIL

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

        @Guanhong said in Weird behavior of QProcess and multiple qoutes:

        << "'"" << strSSID << ""'";

        Why do you quote this? It's not needed at all - every value in the QStringList is passed as one parameter to your app. That's the reason why you should not use the other call - to avoid useless and wrong quotes.

        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
        • G Offline
          G Offline
          Guanhong
          wrote on last edited by
          #14

          @Christian-Ehrlicher
          thank you for your swift reply

          actually in my project, strSSID is a variable, it is delivered by other parameters, here I just made it a constant for convenience.

          I changed
          arguments << "-i" << "wlan0" << "set_network" << "0"<< "ssid" << "'"" << strSSID << ""'";
          to
          arguments << "-i" << "wlan0" << "set_network" << "0"<< "ssid" << "'"" + strSSID + ""'";

          it still FAILed.
          could you help me?

          jsulmJ 1 Reply Last reply
          0
          • G Guanhong

            @Christian-Ehrlicher
            thank you for your swift reply

            actually in my project, strSSID is a variable, it is delivered by other parameters, here I just made it a constant for convenience.

            I changed
            arguments << "-i" << "wlan0" << "set_network" << "0"<< "ssid" << "'"" << strSSID << ""'";
            to
            arguments << "-i" << "wlan0" << "set_network" << "0"<< "ssid" << "'"" + strSSID + ""'";

            it still FAILed.
            could you help me?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #15

            @Guanhong Please read once more what @Christian-Ehrlicher wrote. Your change is NOT what he wrote...

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

            1 Reply Last reply
            1
            • G Offline
              G Offline
              Guanhong
              wrote on last edited by
              #16

              @jsulm thank you.
              I think quotes are necessary, because there is a single quote outside a double quote.
              I need to process the following command by QProcess, could you show me how?
              pa_cli -i wlan0 set_network 1 ssid '"hima24g"'

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

                Again: there is no need to quote an argument when using QProcess::start() with QStringList - they are only needed on the command line so bash/cmd.exe/whatever knows what a single argument is! Your ssid is hima24g and not "hima24g" or 'hima24g' ... or?

                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
                • G Offline
                  G Offline
                  Guanhong
                  wrote on last edited by
                  #18

                  @Christian-Ehrlicher
                  Even if there are single quotes and double quotes in the command, is there no need to add quotes? I looked at earlier replies, it seems that quotes are need.

                  I just removed quotes and changed my codes to
                  arguments << "-i" << "wlan0" << "set_network" << "0"<< "ssid" << strSSID ;
                  FAILed too.

                  jsulmJ 1 Reply Last reply
                  0
                  • G Guanhong

                    @Christian-Ehrlicher
                    Even if there are single quotes and double quotes in the command, is there no need to add quotes? I looked at earlier replies, it seems that quotes are need.

                    I just removed quotes and changed my codes to
                    arguments << "-i" << "wlan0" << "set_network" << "0"<< "ssid" << strSSID ;
                    FAILed too.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #19

                    @Guanhong Then add proper error handling and also read from std error of your process to see whether it prints any errors.

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

                    G 1 Reply Last reply
                    2
                    • jsulmJ jsulm

                      @Guanhong Then add proper error handling and also read from std error of your process to see whether it prints any errors.

                      G Offline
                      G Offline
                      Guanhong
                      wrote on last edited by
                      #20

                      @jsulm
                      QString strResult4 = prcsWlan4.readAllStandardOutput();
                      strResult4 is FAIL

                      jsulmJ 1 Reply Last reply
                      0
                      • G Guanhong

                        @jsulm
                        QString strResult4 = prcsWlan4.readAllStandardOutput();
                        strResult4 is FAIL

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #21

                        @Guanhong said in Weird behavior of QProcess and multiple qoutes:

                        readAllStandardOutput()

                        I was talking about std ERROR (https://doc.qt.io/qt-5/qprocess.html#readAllStandardError)...

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

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

                          Please run it on the command line. Maybe you don't have the proper privileges.

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

                          G 1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            Please run it on the command line. Maybe you don't have the proper privileges.

                            G Offline
                            G Offline
                            Guanhong
                            wrote on last edited by
                            #23

                            @Christian-Ehrlicher
                            I have run it on the command line, it is no problem.

                            Christian EhrlicherC 1 Reply Last reply
                            0
                            • G Guanhong

                              @Christian-Ehrlicher
                              I have run it on the command line, it is no problem.

                              Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #24

                              @Guanhong Please show how you run it on the command line

                              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
                              • G Offline
                                G Offline
                                Guanhong
                                wrote on last edited by
                                #25

                                @Guanhong said in Weird behavior of QProcess and multiple qoutes:

                                <

                                wpa_cli -i wlan0 set_network 1 ssid '"hima24g"'
                                I run it on an Ubuntu console, and it can run successfully

                                jsulmJ Christian EhrlicherC 2 Replies Last reply
                                0
                                • G Guanhong

                                  @Guanhong said in Weird behavior of QProcess and multiple qoutes:

                                  <

                                  wpa_cli -i wlan0 set_network 1 ssid '"hima24g"'
                                  I run it on an Ubuntu console, and it can run successfully

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #26

                                  @Guanhong said in Weird behavior of QProcess and multiple qoutes:

                                  wpa_cli -i wlan0 set_network 1 ssid '"hima24g"'

                                  wpa_cli -i wlan0 set_network 1 ssid hima24g
                                  

                                  should work just as good

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

                                  1 Reply Last reply
                                  0
                                  • G Guanhong

                                    @Guanhong said in Weird behavior of QProcess and multiple qoutes:

                                    <

                                    wpa_cli -i wlan0 set_network 1 ssid '"hima24g"'
                                    I run it on an Ubuntu console, and it can run successfully

                                    Christian EhrlicherC Offline
                                    Christian EhrlicherC Offline
                                    Christian Ehrlicher
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #27

                                    set_network 1

                                    is not

                                    "set_network" << "0"

                                    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
                                    1
                                    • G Offline
                                      G Offline
                                      Guanhong
                                      wrote on last edited by
                                      #28

                                      wpa_cli -i wlan0 set_network 1 ssid hima24g
                                      without quotes, it does not work on my console.

                                      set_network 1 or set_network 0 does not matter.
                                      It depends.

                                      jsulmJ 1 Reply Last reply
                                      0
                                      • G Guanhong

                                        wpa_cli -i wlan0 set_network 1 ssid hima24g
                                        without quotes, it does not work on my console.

                                        set_network 1 or set_network 0 does not matter.
                                        It depends.

                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #29

                                        @Guanhong So, did you try to print out https://doc.qt.io/qt-5/qprocess.html#readAllStandardError ?

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

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

                                          Looks like wpa_cli really needs additional double quotes... strange and weird program (see google for a lot of confusion due to this behavior).
                                          So it must be

                                          arguments << "-i" << "wlan0" << "set_network" << "0"<< "ssid" << "\"" + strSSID + "\"";
                                          

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

                                          G 1 Reply Last reply
                                          2

                                          • Login

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