Problema com aspas ao redor dos nomes dos arquivos no shell de comando do Windows

6

Eu tenho o Windows XP Home SP3 em execução. Tentando executar este comando:

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

Funciona bem (ignore os nomes exatos do programa e arquivo). No entanto, ao citar o último argumento, recebo um erro:

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.

Quando executado sem cmd /c , mas diretamente, ambas as linhas de comando são executadas sem erros. Eu usei o cmd /c para depurar um problema semelhante que tive com system chamadas de um programa em C.

O que há de errado com cmd aqui?

    
por Eli Bendersky 28.01.2011 / 09:08

1 resposta

7

Isso é o que o help cmd diz sobre as citações:

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.

Portanto, duplique a primeira e a última aspas e isso deve funcionar:

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