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 arguments problem
Forum Update on Monday, May 27th 2025

Qprocess arguments problem

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 9.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.
  • E Offline
    E Offline
    eldoradofm
    wrote on 15 Mar 2012, 17:03 last edited by
    #1

    I'm having a problem with arguments.

    I want to start an external program like this:
    programname -in="path to file with spaces in path"

    I tried this:

    @process.start("programname -in=""C:\Documents and Settings\test.ext""");@

    I get response from program:
    Input file 'C:\Documents' doesn't exist!

    So i changed it to:

    @process.start("programname -in="""C:\Documents and Settings\test.ext"""");@

    But then i get the following:
    Input file '"C:\Documents and Settings\test.ext"' doesn't exist!

    I've searched all over the internet for a solution. How can i make this work?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 15 Mar 2012, 18:26 last edited by
      #2

      Did you try to pass the arguments in a string list?

      @
      QString progName = "programname";
      QStringList arguments;
      argument << "-in="C:\Documents and Settings\test.ext"";
      process.start(progName, arguments);
      @

      This should avoid the space based argument parsing, which cries for errors if you have spaces within an argument :)

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • E Offline
        E Offline
        eldoradofm
        wrote on 15 Mar 2012, 21:20 last edited by
        #3

        Yes i also tried it like that.
        But then the program says that i used wrong arguments.
        When i change it to:

        @
        QString progName = "programname";
        QStringList arguments;
        arguments << "-in="C:\test.ext"";
        process.start(progName, arguments);
        @

        And i move the file to C:\test.ext i get the message:
        Input file '"C:\test.ext"' doesn't exist!

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on 15 Mar 2012, 21:22 last edited by
          #4

          And it does work from the command line?

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • E Offline
            E Offline
            eldoradofm
            wrote on 15 Mar 2012, 21:27 last edited by
            #5

            Yes when i type from command line: @programname -in="C:\Documents and Settings\test.ext"@
            Then it works.
            It works with 1: \ and with 2: \.
            Somehow i can't post the above line on this forum with 1 \ in it.

            It also works with @programname -in="C:/Documents and Settings/test.ext"@ from the command line.

            Are there other things i can try to make it working?

            1 Reply Last reply
            0
            • E Offline
              E Offline
              eldoradofm
              wrote on 17 Mar 2012, 18:02 last edited by
              #6

              With suggestions from others i came to a working example:
              @process.start(""programname "-in=""""C:/Documents and Settings/test.ext""""");@
              Now i'm trying to find a working solution for when i use QStringList.

              1 Reply Last reply
              0
              • E Offline
                E Offline
                eldoradofm
                wrote on 17 Mar 2012, 18:58 last edited by
                #7

                I can only get it to work like this with QStringlist:
                @
                QStringList test;
                test << ""programname" << "-in="""C:/Documents and Settings/test.ext""""";

                QString test2;
                test2 = arguments.join(" ");

                process.start(test2);
                @

                But when i use this:
                @
                QString program = "programname";
                QStringList arguments;
                arguments << "-in=C:/Documents and Settings/test.ext";
                process.start(program,arguments);
                @

                It doesn't work. I don't know anymore why i have this problems.

                But for now i can continue with the single QStringlist that i join in a QString.
                If anyone has other suggestions that i can try please let me know.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on 19 Mar 2012, 11:46 last edited by
                  #8

                  The only suggestion is: Use what works for you! There is no need to change a running system.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0

                  1/8

                  15 Mar 2012, 17:03

                  • Login

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