Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-49641

QProcess::start removes some quotes in wrong way

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.3.2
    • Core: Other
    • None

    Description

      Let's consider the following example.

      Source code for a.cmd is:

      a.cmd
      @echo off
      echo allargs=%*
      echo arg1=%1
      echo arg2=%2
      echo arg3=%3
      echo arg4=%4
      echo arg5=%5
      echo well done
      

      Let's start that program with following command line from windows command prompt

      a.cmd "" "alfa=a,b,c"
      

      Please note 2 important things:

      1. First arg is emtpy (that is what we want to be)
      2. Second arg is quoted, because we want to be interpreted as single entity.

      The output of described start is good and is what we want [O1]:

      allargs="" "alfa=a,b,c"
      arg1=""
      arg2="alfa=a,b,c"
      arg3=
      arg4=
      arg5=
      well done
      

      Now let's decide to use Qt to start our program:

        QProcess *process = new QProcess();
        QString cmd = "a.cmd \"\" \"alfa=a,b,c\"";
        process->start( cmd );
      

      After Qt's start, we get new output [O2]:

      allargs=alfa=a,b,c
      arg1=alfa
      arg2=a
      arg3=b
      arg4=c
      arg5=
      well done
      

      This output [O2] is totally different from the desired output [O1].

      Let's check what Qt did actually started (via Process Explorer from Sysinternals). It shows us the next command line:

      C:\Windows\system32\cmd.exe /c a.cmd  alfa=a,b,c
      

      It seems Qt somehow ruined our original command line. The documentation says that QProcess::start somehow
      unquotes arguments and packs them back. Ok, this is not the problem.

      But as we see, after Qt's unquotation/conversion of command line, the command line contains 2 problems.


      PROBLEM 1. The first emtpy argument ("") is thrown away.
      That is wrong behavior! We need 1st argument to be empty!

      PROBLEM 2. The second argument ("alfa=a,b,c") lacks quotes!
      That is wrong behavior! In windows, symbols "=" and "," are threatened as argument delimiters.
      That's why our script shows 4 different args insteat of just one.

      We think that in case we want to really pass alfa=a,b,c without quotes so cmd.exe will consider them as arguments delimiters, we will pass them to `QProcess::start` without quotes. But current `QProcess::start` implementation is not the case: it always removes our quotes!

      Please consider Microsoft documentation on cmd.exe:

      The following special characters require quotation marks: & < > [ ] { } ^ = ; ! ' + , ` ~ [white space]

      from here https://technet.microsoft.com/en-us/library/bb490880.aspx

      so, PROBLEM 2 is cmd-related, because cmd.exe requires quotation marks on symbols stated above.


      Please, consider our report and fix QProcess::start appropriately.

      Thank you very much!

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            pavelvasev Pavel Vasev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes