Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

COMSPEC vs. _CMDSPEC

Jun
1,092
48
I've noticed that there are two variables that seem to contain the same thing. Is there a difference? Are they used in different ways, or are they interchangeable?
 
From the help:

_CMDSPEC returns the full pathname of the command processor.

I think COMSPEC is the same and may exist for CMD compatibility.
 
Code:
PS E:\utils> $env:comspec
C:\WINDOWS\system32\cmd.exe
PS E:\utils> tcc echo %_cmdspec
C:\Program Files\JPSoft\TCMD36\TCC.EXE
PS E:\utils>

_CMDSPEC is TCC specific,
that is,
it will only return TCC.EXE

Joe
 
There may be a subtle (or not so subtle) difference. Traditionally, COMSPEC names the default command processor.

I vaguely remember a discussion, decades ago, about whether, in Windows, C's system() function honored COMSPEC. I don't recall the upshot of that discussion. Today it doesn't seem important.
 
I just started 4DOS,
and these are the results;

1783963755170.webp


Not sure if I still have TCC installed in my Windows 98 system...

Joe
 
COMSPEC is an environment variable. Lots of other programs — yea, even unto the days of MS-DOS — can read this environment variable. Some may even depend on it.

_CMDSPEC is an internal variable. External programs generally won't be able to access it.
 
COMSPEC is a command interpreter that other programs will use to execute commands.
I have a few wrappers written in TCC, which had to redefine ComSpec back to CMD to make wrapped programs behave.
 
Back
Top