cmd
can be grouped with /c
between the same pair of quotes.
C:\>"cmd /c" echo 1
1
C:\>"cmd.exe /c" echo 1
The system cannot find the path specified.
C:\>"cmd /c"echo 1
1
C:\>cmd /c"echo 1
1
C:\>c"md /c"echo 1"
1
I noticed that cmd.exe
cannot be quoted in that way, and if there is no space between the closing quotation mark and the command, a leading space is supplied.
How are the quotes parsed? Some basic information that might help: How does the Windows Command Interpreter (CMD.EXE) parse scripts?
Update:
When I copy another program which prints its command-line arguments to the working directory and rename it to cmd.exe
, I found they are calling two different executables.
C:\>cmd /c echo 1
...calling my program...
arg0 is <cmd>
arg1 is </c>
arg2 is <echo>
arg3 is <1>
C:\>"cmd /c" echo 1
1
And the leading space is related to the number of quotes.
C:\>"cmd /c"echo 1
1
C:\>"cmd /c"e"cho 1
1
C:\>"cm"d /c"echo 1
1
C:\>"cm"d /c"ech"o 1
1
C:\>"c"m"d /c"echo 1
1
C:\>"c"m"d /c"ech"o 1
1
C:\>"c"m"d" /c"echo 1
1
C:\>"c"m"d" /c"ec"ho 1
1
C:\>"c"m"d" "/c"echo 1
1
C:\>"c"m"d" "/"c"echo 1
Microsoft Windows [Version 10.0.19042.685]
(c) 2020 Microsoft Corporation. All rights reserved.
C:\>exit