I have Windows XP Home SP3 running. Trying to run this command:

cmd /c "C:\Program Files\TortoiseSVN\bin\subwcrev.exe" .. ..\Modules\getbuildinfo.c Win32-temp-Debug\getbuildinfo2.c

It works fine (ignore the exact program and file names). However, when quoting the last argument, I get an error:

cmd /c "C:\Program Files\TortoiseSVN\bin\subwcrev.exe" .. ..\Modules\getbuildinfo.c "Win32-temp-Debug\getbuildinfo2.c"

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

When run without cmd /c but directly, both command lines run without errors. I used the cmd /c to debug a similar problem I had with system calls from a C program.

What is wrong with cmd here?


This is what help cmd says about quoting:

If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (") characters:

  1. If all of the following conditions are met, then quote characters on the command line are preserved:

    • no /S switch
    • exactly two quote characters
    • no special characters between the two quote characters, where special is one of: &<>()@^|
    • there are one or more whitespace characters between the two quote characters
    • the string between the two quote characters is the name of an executable file.
  2. Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character.

So double the first and last quotes and it should work:

cmd /c ""C:\Program Files\TortoiseSVN\bin\subwcrev.exe" .. ..\Modules\getbuildinfo.c "Win32-temp-Debug\getbuildinfo2.c""
| improve this answer | |
  • 1
    This applies to system as well, so don't forget the extra pair of quotes around the entire command! – Rufflewind Mar 3 '15 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.