Передача цитат в цитатах в cmd.exe - PullRequest
1 голос
/ 20 января 2011

Мне нужно запустить appcmd.exe, но запустить cmd.exe для запроса веб-сайта IIS, а также мне нужно перенаправить вывод.

Команда должна выглядеть следующим образом:

cmd /c "c:\windows\system32\inetsrv\appcmd.exe list site MySite" > c:\output.txt  

Это работает нормально, однако я сталкиваюсь с проблемами, когда в моих путях есть пробелы, и в этом случае мне нужно использовать кавычки.В идеале я бы сделал:

cmd /c ""c:\windows\system32\inetsrv\appcmd.exe" list site "MySite"" > "c:\output.txt"  

, но это не сработает - есть идеи?

Ответы [ 3 ]

2 голосов
/ 02 июля 2013

На экране справки, отображаемом «cmd / c», отображается это сообщение:

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

Используйте «старое» поведение, упомянутое в пункте 2. Введите все после / c, как обычно, но окружитепосле / с в кавычках.Например:

"c:\windows\system32\inetsrv\appcmd.exe" list site "MySite" > "c:\output.txt"

становится

cmd /c ""c:\windows\system32\inetsrv\appcmd.exe" list site "MySite" > "c:\output.txt""
0 голосов
/ 24 января 2011

Это может сработать:

cmd /c "'c:\windows\system32\inetsrv\appcmd.exe' list site 'MySite'" > "c:\output.txt"
0 голосов
/ 24 января 2011
cmd /c c:\windows\system32\inetsrv\appcmd.exe list site MySite > c:\output.txt
...