experchange > win2000.* > win2000.cmdprompt.admin

Gregory Mamayek (07-18-03, 07:40 PM)
Gang:\>

How come some files fire using .cmd, while others use .bat?
When would you use either one?

Is it because .cmd is for execution, while .bat is used to provide a
data source (ie. like web page .htm using SQL to call data source .bat)?
Gregory Mamayek (07-18-03, 07:46 PM)
Gang:\>

I looked at the extensions, so I see the different properties.

Also, is debug a good way to get more information about what's going on
compared to the last result: 0x0 field in scheduled tasks?

Gregory Mamayek wrote:
[..]
Dean Wells [MVP] (07-18-03, 07:50 PM)
No difference in behavior ... whatsoever ... in the context of this
newsgroup at least.

Legacy extension implying batch of commands = .BAT
Uplevel extension implying shell script = .CMD

..BAT = common to x-DOS operating systems
..CMD = used by OS/2 and introduced in Windows NT4

Dean
Gregory Mamayek (07-18-03, 08:15 PM)
Dean:

Thanx for reply.

I am running WIN2K, but I do see a difference in that the .cmd's work,
while the .bat's don't. If I understand you correctly, this may be due to
the OS, or maybe it's the commands I'm using within the batch files.

I will have to play with some more examples to examine their behavior.

The best example is Ritchie's HTML CMD tool. It didn't work when I named
the batch file with .bat, but worked when I used .cmd.

Just a newbie...LOL

"Dean Wells [MVP]" wrote:
[..]
Dean Wells [MVP] (07-18-03, 09:16 PM)
I've not seen Richie's script, can you post it?

I've discovered no differences in the behavior between .BAT and .CMD
from Windows 2000 onwards.

Dean
Ritchie (07-18-03, 09:37 PM)
"Dean Wells [MVP]" <dwells> wrote in message news:2768
> No difference in behavior ... whatsoever ... in the context of this
> newsgroup at least.


I don't mean to be picky, but that's not strictly true. Create two copies
of the script below, save one as a .bat, the other as a .cmd:-

@echo off&setlocal ENABLEEXTENSIONS
call :func&&echo/I'm a cmd||echo/I'm a bat
goto :EOF

:func
md;2>nul
set var=1

I think .cmd is the preferred extension for NT/2000/XP/2003 scripts.
NuT CrAcKeR (07-18-03, 10:07 PM)
Since no one else has added this to the mix... here it goes.

..bat extetions are executed in a 16bit VDM while .cmd extentions are
executed in a 32bit VDM. This has implications for scripts that may need to
access shared memory from other processes or applications.

..... this is an addendum to what the others in the group have already said.

NuTs

"Gregory Mamayek" <gmamayek> wrote in message
news:4280
[..]
Dean Wells [MVP] (07-18-03, 10:43 PM)
Hi Richie,

I've tested your enclosed syntax on 2000, XP and 2003. The bahavior of
the .BAT script is is identical to that of the .CMD script on all 3
platforms ... unless I'm missing the difference you're attempting to
exhibit.

Dean
Dean Wells [MVP] (07-18-03, 10:56 PM)
I stand corrected ... I've just this seond noticed the difference
(opening my eyes must have helped ;)

That's an interesting behavioral difference ... I'll do some digging and
see what else turns up.

Dean
Dean Wells [MVP] (07-18-03, 11:35 PM)
It appears to require 3 components (at least that I've found so far) in
order to trigger the behavioral difference -

1. Use of a call statement
2. An error of some kind
3. an environment modification

Does this concur with your own findings?

Dean
Ritchie (07-19-03, 11:16 AM)
"Dean Wells [MVP]" <dwells> wrote in message news:1992
> It appears to require 3 components (at least that I've found so far) in
> order to trigger the behavioral difference -
> 1. Use of a call statement
> 2. An error of some kind
> 3. an environment modification


It's simply that a .cmd file using the SET command to assign a value to
a variable, results in the errorlevel being cleared (set to zero). Doing
the same in a .bat file does not change the errorlevel. See this batch
file, and the output below for an example:-

------------ a.bat/a.cmd starts below ------------------
@echo off & setlocal ENABLEEXTENSIONS
ver>nul
echo/After the VER command, errorlevel is %errorlevel%
md;2>nul
echo/Using MD incorrectly, errorlevel is %errorlevel%
set var=1
echo/After setting var, errorlevel is %errorlevel%
------------ a.bat/a.cmd ends above --------------------

<SCREEN SHOT>

d:\data\bat\help>a.cmd
After the VER command, errorlevel is 0
Using MD incorrectly, errorlevel is 1
After setting var, errorlevel is 0

d:\data\bat\help>a.bat
After the VER command, errorlevel is 0
Using MD incorrectly, errorlevel is 1
After setting var, errorlevel is 1

<\SCREEN SHOT>
Phil Robyn (07-21-03, 03:40 AM)
Tim Hill wrote:

> There are NO differences between a .BAT and a .CMD script when executed on a
> platform that understands the .CMD file type (NT et al). If I recall
> correctly, the .CMD type was inherited from OS/2.
> One common "urban myth" is that .BAT files are somehow run in a 16-bit
> NTVDM. Not so, they are tun by CMD.EXE just like .CMD files.
> The only real use of the two file types is to prevent backward
> compatibility. If I write a script that uses NT-only features (e.g. "FOR
> /D") then by naming it .CMD I prevent anyone accidentally running it on a
> Win9x box.
> -Tim


Are you *the* Tim Hill (of _Windows NT Shell Scripting_ fame)?
Dean Wells [MVP] (07-21-03, 03:56 AM)
RE: "NO differences" - An opinion with which I would have recently
agreed ... please note the earlier posts within this thread, most
specifically those from Ritchie.
Dean Wells [MVP] (07-21-03, 06:40 PM)
Thanks for the clarification Mark.

For the sake of my own sanity, do you consider this the definitive list
of differences and, of equal importance, what was the goal behind these
differences (assuming it's not simply an oddity)?

Dean
Mark Zbikowski \(MSFT\) (07-21-03, 09:30 PM)
Well... I peeked at the sources. The differences stem from
a desire in OS/2 to "fix" COMMAND.COM; to wit, that every
call (with extensions enabled) would change the errorlevel
in a manner so you could detect if a command failed or not.

Now... without spending a ton of time with the sources, I don't
know if this REALLY addressed that issue or not.

Similar Threads