I want to run iisexpress inside cmd and start it from powershell. I have a strange issue with escaping double quotes. My original powershell command is
Start-Process 'cmd' -ArgumentList '/k "C:/Program Files/IIS Express/iisexpress.exe" /config:"d:\Repo\app\applicationhost.config" /apppool:"Clr4IntegratedAppPool"'
It fails with
'C:/Program' is not recognized as an internal or external command,
operable program or batch file.
There is clearly some issues with double quotes, however when I try to run iis without arguments it actually starts it
Start-Process 'cmd' -ArgumentList '/k "C:/Program Files/IIS Express/iisexpress.exe"'
I noticed it feels fine until I type a double quote after iisexpress.exe"
. For instance, just Start-Process 'cmd' -ArgumentList '/k "C:/Program Files/IIS Express/iisexpress.exe" /config:"
is failing with 'C:/Program' is not recognized
, but Start-Process 'cmd' -ArgumentList '/k "C:/Program Files/IIS Express/iisexpress.exe" /config:
also fails, but it tells that I should provide a value for the argument.
All in all, how to avoid the issue with arguments for iisexpress?
You've run into a cmd.exe
parsing "quirk", which you can avoid by enclosing everything that follows /k
(or /c
) in "..."
(incredibly, this does then not require escaping the then embedded "
chars):
Start-Process 'cmd' -ArgumentList '/k " "C:/Program Files/IIS Express/iisexpress.exe" /config:"d:\Repo\app\applicationhost.config" /apppool:"Clr4IntegratedAppPool" "'
The problem occurs when both a double-quoted executable path and double-quoted arguments are present and there is no overall "..."
enclosure. (There are situational exceptions, but overall "..."
enclosure is the safe choice.)