Parameters 将引号中的引号传递给cmd.exe

Parameters 将引号中的引号传递给cmd.exe,parameters,cmd,quotes,Parameters,Cmd,Quotes,我需要运行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 "

我需要运行
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"  
但这行不通-有什么想法吗?

这可能行得通:

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"
cmd /c ""c:\windows\system32\inetsrv\appcmd.exe" list site "MySite" > "c:\output.txt""

“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.
变成

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