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. System() function for the path including blanks.
Qt 6.11 is out! See what's new in the release blog

System() function for the path including blanks.

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 2.2k Views 1 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.
  • P Offline
    P Offline
    pnk003
    wrote on last edited by
    #1

    Dear Qt developer and experts.

    I found that the the system() function does not work when the path including blanks.
    Would you check this? I spend a day for this. ^^;

    The following code using the path including blanks does not work.

    sprintf( buff, " "C:\\Program Files (x86)\\tool\\tool.exe" argument");
    system( buff );;

    If the path does not have blank, the system() function works well (as follows).

    sprintf( buff, "D:\directory\GUI\tool\QC\tool.exe");
    system( buff );;

    Thank you very much.
    I really appreciate to the Qt developers. It the the best tool.

    Sincerely Yours,

    Ick-Sung Choi.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Do you get into your "buff" variable the expected string that you have passed ? Try printing it.

      157

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mehrdadsilver
        wrote on last edited by
        #3

        I have this problem too :(

        Mehrdad Abdolghafari, Be silver

        1 Reply Last reply
        0
        • B Offline
          B Offline
          blueshift
          wrote on last edited by
          #4

          Use this:
          @sprintf(buff, "C:\"Program Files"\CCleaner\CCleaner64.exe"); @

          Note the "Program Files" put in quotes using Escape character(")

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pnk003
            wrote on last edited by
            #5

            Dear experts.
            Thank you very much for comment and advices.
            Yes. I tried to print the buff string. The string is executed well when I put it in DOS cmd.exe.

            I wrote the string to "run.bat" file. and I execute the "run.bat" using system("run.bat").

            Thank you blueshift for your advice.
            I will try it.

            Thank you very much.

            Sincerely Yours,

            Ick-Sung Choi.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #6

              For future reference none of this has anything to do with Qt.

              system() is a C/C++ standard library function.
              The need to quote paths containing spaces is s function of the command shell that system() launches on your behalf.
              The way you escape quotes and backslashes in a C literal string is governed by the C/C++ language.

              If you want a Qt equivalent please look at the QProcess class.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pnk003
                wrote on last edited by
                #7

                Dear ChrisW67.

                Thank you very much for your precious advice.
                I am not good at C++ and Qt .
                I started to study Qt just a month ago. ^^;

                Thank you very much.
                Sincerely Yours,

                Ick-Sung Choi.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  blueshift
                  wrote on last edited by
                  #8

                  Yes ChrisW67 is right. It is advisable to use QProcess for what you intend. Calling system() is highly undesirable.
                  Regards and thanks,
                  blueshift

                  1 Reply Last reply
                  0

                  • Login

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