Weird parsing rule for cmd command #15427

Open
opened 2026-01-31 04:38:22 +00:00 by claunia · 0 comments
Owner

Originally created by @SainoNamkho on GitHub (Oct 4, 2021).

Windows Terminal version (or Windows build number)

10.0.19042.0, 1.4.3243.0

Other Software

No response

Steps to reproduce

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

note that there's a space in front of 1 in the "cmd /c"echo 1 case

Expected Behavior

When I run it in mintty.exe, command is parsed properly

$ cmd
Microsoft Windows [Version 10.0.19042.685]
(c) 2020 Microsoft Corporation. All rights reserved.

D:\>cmd /c echo 1
cmd /c echo 1
1

D:\>"cmd /c"echo 1
"cmd /c"echo 1
The filename, directory name, or volume label syntax is incorrect.

D:\>"cmd /c" echo 1
"cmd /c" echo 1
The filename, directory name, or volume label syntax is incorrect.

And win+r run dialog box errs in `Windows cannot find 'cmd /c'. Make sure you typed the name correctly, and then try again."

Actual Behavior

It seems this command is parsed specially. When I copied a program named cmd.exe which prints command-line arguments to the current directory, it's not called in this case.

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
Originally created by @SainoNamkho on GitHub (Oct 4, 2021). ### Windows Terminal version (or Windows build number) 10.0.19042.0, 1.4.3243.0 ### Other Software _No response_ ### Steps to reproduce ```cmd 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 ``` note that there's a space in front of 1 in the `"cmd /c"echo 1` case ### Expected Behavior When I run it in mintty.exe, command is parsed properly ```cmd $ cmd Microsoft Windows [Version 10.0.19042.685] (c) 2020 Microsoft Corporation. All rights reserved. D:\>cmd /c echo 1 cmd /c echo 1 1 D:\>"cmd /c"echo 1 "cmd /c"echo 1 The filename, directory name, or volume label syntax is incorrect. D:\>"cmd /c" echo 1 "cmd /c" echo 1 The filename, directory name, or volume label syntax is incorrect. ``` And <kbd>win+r</kbd> run dialog box errs in `Windows cannot find 'cmd /c'. Make sure you typed the name correctly, and then try again." ### Actual Behavior It seems this command is parsed specially. When I copied a program named `cmd.exe` which prints command-line arguments to the current directory, it's not called in this case. ```cmd 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 ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#15427