The Windows command prompt (cmd.exe
) has an optional /s
parameter, which modifies the behavior of /c
(run a particular command and then exit) or /k
(run a particular command and then show a shell prompt). This /s
parameter evidently has something to do with some arcane quote handling.
The docs are confusing, but as far as I can tell, when you do cmd /c
something
, and the something
contains quotation marks, then by default cmd
will sometimes strip off those quotes, and /s
tells it to leave them alone.
What I don't understand is when the quote removal would break anything, because that's the only time /s
("suppress the default quote-removal behavior") would be necessary. It only removes quotes under a certain arcane set of conditions, and one of those conditions is that the first character after the /c
must be a quotation mark. So it's not removing quotes around arguments; it's either removing quotes around the path to the EXE you're running, or around the entire command line (or possibly around the first half of the command line, which would be bizarre).
- If the path to the EXE is quoted, e.g.
cmd /c "c:\tools\foo.exe" arg1 arg2
, then quotes are unnecessary, and ifcmd
wants to remove them, fine. (It won't remove them if the path has a space in the name -- that's another of the arcane rules.) I can't imagine any reason to suppress the quote removal, so/s
seems unnecessary. - If the entire command line is quoted, e.g.
cmd /c "foo.exe arg1 arg2"
, then it seems like quote removal would be a necessity, since there's no EXE namedfoo.exe arg1 arg2
on the system; so it seems like opting out of quote removal using/s
would actually break things. (In actual fact, however, it does not break things:cmd /s /c "foo.exe arg1 arg2"
works just fine.)
Is there some subtlety to /s
that's eluding me? When would it ever be necessary? When would it even make any difference?
/s
helped him: #356488 I don't know exactly what whatRunProgram()
did/does, but trying to repro the problem on the command line got me nowhere. All I know is that cmd.exe's command parsing (especially with escaping characters) can be bizarre at times, so I have no doubt that/s
is useful in at least one occasion. – Nickolenicks/s
works is incorrect. However, none of the upvoted answers seem to correct you description, so I'm not sure what to think. – GeralyngeraniaceousWindows 7 x64
it works like/s
is always used. – Tyishatyke@
as a command start character to avoid quotes stripping:cmd.exe /c @"..." ...
– Tyishatyke