2011-01-20 114 views
1

我需要運行appcmd.exe,但運行cmd.exe來查詢IIS網站,我也需要重定向輸出。將引號傳遞給cmd.exe

的命令應該是這樣的:

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" 

但這不起作用 - 任何想法?

回答

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

這可能會實現:

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

通過 「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後加引號。例如:

"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"" 
相關問題