how to escape " in cmd.exe /c parameters?
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Orient Looping
--
Chapters
00:00 How To Escape &Quot; In Cmd.Exe /C Parameters?
00:56 Accepted Answer Score 14
01:42 Thank you
--
Full question
https://superuser.com/questions/1213094/...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#windows #commandline #cmdexe
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Orient Looping
--
Chapters
00:00 How To Escape &Quot; In Cmd.Exe /C Parameters?
00:56 Accepted Answer Score 14
01:42 Thank you
--
Full question
https://superuser.com/questions/1213094/...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#windows #commandline #cmdexe
#avk47
ACCEPTED ANSWER
Score 14
Funny that cmd.exe actually contains the answer.
Here's a snipped from cmd /?
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
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.
So in your case it would be:
C:\>C:\Windows\System32\cmd.exe /C ""C:\Program Files (x86)\gs\uninstgs.exe" "C:\Program Files (x86)\gs\gs8.63\uninstal.txt""
That said, it would also be possible to use the 8.3 short names and thus truncate Program Files to Progra~1 or Progra~2. Even more, you could use relative paths and first navigate to c:\Program Files(x86) before executing your command. Your command would then become:
C:\>cd /d "c:\Program Files (x86)" && C:\Windows\System32\cmd.exe /C ".\gs\uninstgs.exe .\gs\gs8.63\uninstal.txt"