I have a file a.cmd
. Path to the file is C:\Program Files\a\a.cmd
and C:\Program Files\a
is in PATH
environment variable.
When I invoke a.cmd
from PowerShell (v. 7.2) I see that a process with the following command line is created:
C:\WINDOWS\system32\cmd.exe /c ""C:\Program Files\a\a.cmd""
I wonder what the quotes add (OS, PowerShell or something else) and how cmd.exe handles the arguments list. When I replace cmd.exe with a custom .NET program (eg. by changing COMSPEC
env variable) I see following command line args (from the cmd.exe replacement perspective):
arg 0: /c
arg 1: C:\Program
arg 2: Files\a\a.cmd
and whole command line is (System.Environment.CommandLine
):
replaced.exe /c C:\Program Files\a\a.cmd
and it make sense to me.
As I know an OS parses a command line and passes it to a process. How does cmd.exe handle these arguments and how can cmd.exe open proper file?