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)?
--
Cordially,
Greg
A+ BS MCSE Web Developer
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?
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
--
Dean Wells [MVP / Windows platform]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
"Gregory Mamayek" <gmam...@dllr.state.md.us> wrote in message
news:3F183117...@dllr.state.md.us...
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
I've discovered no differences in the behavior between .BAT and .CMD
from Windows 2000 onwards.
Dean
--
Dean Wells [MVP / Windows platform]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
"Gregory Mamayek" <gmam...@dllr.state.md.us> wrote in message
news:3F183930...@dllr.state.md.us...
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.
--
Ritchie
.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" <gmam...@dllr.state.md.us> wrote in message
news:3F183117...@dllr.state.md.us...
Dean
--
Dean Wells [MVP / Windows platform]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
"NuT CrAcKeR" <nutcr...@intenationalhacket.org> wrote in message
news:Ows13gWT...@TK2MSFTNGP10.phx.gbl...
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 / Windows platform]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message
news:bf9iad$cgcjq$1...@ID-156657.news.uni-berlin.de...
That's an interesting behavioral difference ... I'll do some digging and
see what else turns up.
Dean
--
Dean Wells [MVP / Windows platform]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
"Dean Wells [MVP]" <dwe...@mask.msetechnology.com> wrote in message
news:eELLM1WT...@tk2msftngp13.phx.gbl...
1. Use of a call statement
2. An error of some kind
3. an environment modification
Does this concur with your own findings?
Dean
--
Dean Wells [MVP / Windows platform]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message
news:bf9iad$cgcjq$1...@ID-156657.news.uni-berlin.de...
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>
--
Ritchie
Do you know of any further handling differences?
PS - Out of interest, did you just stumble across this one or was it
documented somewhere?
Dean
--
Dean Wells [MVP / Windows platform]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R a m o v e t h e m a s k t o s e n d e m a i l
"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message
news:bfb2a6$cv8fu$1...@ID-156657.news.uni-berlin.de...
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
"Gregory Mamayek" <gmam...@dllr.state.md.us> wrote in message
news:3F183117...@dllr.state.md.us...
> 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)?
--
Phil Robyn
Univ. of California, Berkeley
u n z i p m y a d d r e s s t o s e n d e - m a i l
--
Dean Wells [MVP / Windows platform]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
"Tim Hill" <nos...@span.com> wrote in message
news:%23wSoScy...@TK2MSFTNGP12.phx.gbl...
No, that's the only difference I'm aware of.
> PS - Out of interest, did you just stumble across this one or was it
> documented somewhere?
It was stumbled upon in the 'hangman' script. I think it was Garry D/Musafir
that actually pin-pointed the issue. See this (longish) thread:-
Subject: Minimise DOS prompts
Newsgroups: microsoft.public.win2000.cmdprompt.admin
Date: 2003-04-16 10:37:41 PST
http://groups.google.com/groups?threadm=04d601c3043e%2492ac6180%242f01280a%40phx.gbl
Looks like Tim Hill might have to revise his book, LOL
--
Ritchie
With extensions enabled, PATH/APPEND/PROMPT/SET/ASSOC in .CMD
files will set ERRORLEVEL regardless of error. .BAT sets ERRORLEVEL
only on errors.
--
Disclaimer: This posting is provided "AS IS" with no warranties, and confers
no rights.
"Gregory Mamayek" <gmam...@dllr.state.md.us> wrote in message
news:3F183117...@dllr.state.md.us...
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
--
Dean Wells [MVP / Windows platform]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
"Mark Zbikowski (MSFT)" <Ma...@online.microsoft.com> wrote in message
news:ODYdDP6T...@TK2MSFTNGP12.phx.gbl...
Now... without spending a ton of time with the sources, I don't
know if this REALLY addressed that issue or not.
--
Disclaimer: This posting is provided "AS IS" with no warranties, and confers
no rights.
"Dean Wells [MVP]" <dwe...@mask.msetechnology.com> wrote in message
news:%23tnr%23a6TD...@tk2msftngp13.phx.gbl...
-Tim
"Phil Robyn" <zipp...@uclink.berkeley.edu> wrote in message
news:O6JEWkyT...@tk2msftngp13.phx.gbl...
-Tim
"Ritchie" <qiournvdlirh...@hotmail.com> wrote in message
news:bfg0cl$e82v3$1...@ID-156657.news.uni-berlin.de...
> Not sure about "fame", but yes .. that's me. :)
>
> -Tim
Well, then, I want to thank you so much for writing the book. I
never hesitate to recommend it wholeheartedly to others looking
for a good book about batch file scripting. Any plans for a new
edition? :-)
^ This is very interesting. I'm going to dig down further.
^ Can anyone think of any use fro this feature?
It seems that your news server may be a bit slow so I'll quote part of
another message in this thread:
Mark Zbikowski (MSFT) article <ODYdDP6T...@TK2MSFTNGP12.phx.gbl>...
^ The differences between .CMD and .BAT as far as
^ CMD.EXE is concerned are:
^
^ With extensions enabled, PATH/APPEND/PROMPT/SET/ASSOC
^ in .CMD files will set ERRORLEVEL regardless of error.
^ .BAT sets ERRORLEVEL only on errors.
Cross-platform (95 - NT) compatibility. A batch script written for Windows 95
will be "more likely" to behave as expected on Windows NT as well.
Frank
Thanks for the recommendations :)
-Tim
"Phil Robyn" <zipp...@uclink.berkeley.edu> wrote in message
news:eOCk6T9...@TK2MSFTNGP11.phx.gbl...
Both ran on WIN2K PC in DOS prompt stating what they were. No issue with either.
Ritchie wrote:
--
The first one didn't run, but the second one did (listed further down in
thread).
I'm no expert, still learning the ropes here...LOL