[solved] QProcess Problem with non-wrapped pipe symbol | in argument list

  • Hallo dear qt forum users,

    I have a problem trying to run a command using QProcess on windows. Everything works fine except the interpretation of one argument.

    I am calling the vcbuild.exe to build a visual studio 2008 solution. The call looks like this:
    @QString program = "cmd.exe";
    QStringList arguments;
    arguments << "/c" << getenv(VS90COMNTOOLS) + "\vsvars32.bat"
    << "&" << "vcbuild.exe" << pathToSolution << "Debug|Win32";
    QProcess::execute( program, arguments );@

    The problem is that a name like "Debug|Win32" is a common configuration name for many solutions i want to be built programmatically calling my program which uses QProcess - but the symbol "|" gets treated as a pipe symbol and windows says:
    "The command Win32 is wrong or could not be found."
    (orig. "Der Befehl "Win32" ist entweder falsch geschrieben oder konnte nicht gefunden werden. ")

    If I try using quotes:
    @arguments << [...] << ""Debug|Win32""@
    The error is:
    "vcbuild.exe: Error VCBLD0006: Invalid configuration name: "Debug|WIN32"."
    (orig. "vcbuild.exe: Fehler VCBLD0006: Ungültiger Konfigurationsname: "DEBUG|WIN32".")
    Obviously the quotes are now part of the name such that the pipe symbol is no longer treated as pipe symbol but now the configuration name is wrong. By try and error I found that Qt wraps it by three quotes. It is as if I would write:
    @vcbuild.exe [...] """Debug|Win32"""@

    The workaround would be to put everything into one large string, but that would be my last unwanted choice, because that way I would have to do all the quoting stuff depending on quotes or spaces on my own.

    Does someone know an answer how to solve my problem? Thank you in advance!

  • How does the command line look if you run it manually?

  • If i run it manually it looks like:

    @>%VS90COMNTOOLS%vsvars32.bat & vcbuild.exe D:\Development\Projects\TestProj\Source\TestProj.sln "Debug|Win32"@

  • The "QProcess::start doc":http://qt-project.org/doc/qt-5/qprocess.html#start-3 says "Note that, on Windows, quotes need to be both escaped and quoted."

    Try to play with different number of escaped quotes around "Debug|Win32". Lets start from triple like it is shown in the doc.

    arguments << "/c" << getenv(VS90COMNTOOLS) + "\vsvars32.bat"
    << "&" << "vcbuild.exe" << pathToSolution << """"Debug|Win32"""";

  • Thank you very much for your advice, but it hasn't been the right way either. If I try using more quotes, i get errors like:

    @vcbuild.exe: Error VCBLD0006: Invalid Configuration Name: """DEBUG|WIN32""".@

    in German:
    @vcbuild.exe: Fehler VCBLD0006: Ungültiger Konfigurationsname: """DEBUG|WIN32""".@

    I got right answer on stackoverflow:
    Dmitry Sokolov said:
    "Try to use ^ as an escape character, i.e. "Debug^|Win32". See "cmd Escape Character":http://ss64.com/nt/syntax-esc.html for details."

    • Solved -

  • Great. Thank you for sharing the solution.
    Could you, please, put "[solved]" in front of the title of you original post.

Log in to reply