Important: Please read the Qt Code of Conduct -

Qprocess arguments problem

  • 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?

  • 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 :)

  • 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!

  • And it does work from the command line?

  • 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?

  • 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.

  • 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(" ");


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

    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.

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

Log in to reply