Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Assuming that my shell script is entirely based on DOS commands(dir, cd, etc and not VBS or PowerShell commands), using .cmd or .bat extension for it's name will change something? I mean, it will be executed as the same way and with the same interpreter if using .cmd or .bat extension?

share|improve this question
    
Note that neither extension means any kind of DOS is being used. On Windows NT systems, both extensions are handled by the same cmd.exe interpreter, which is a native Windows program. –  grawity Oct 9 '13 at 17:26

1 Answer 1

up vote 2 down vote accepted

There is a well written answer from stackoverflow.

So, no it doesn't affect your commands. The handling of the ERRORLEVEL is just different. In cmd, the ERRORLEVEL will be set regardless if there is an error or not.

Bat only does, if there is an error.

From Wikipedia:

New Quote from Wikipedia

The only known difference between .cmd and .bat file execution is that in a .cmd file the ERRORLEVEL variable changes even on a successful command that is affected by Command Extensions (when Command Extensions are enabled), whereas in .bat files the ERRORLEVEL variable changes only upon errors.

The source for the Wikipedia quote above is actually based on this news group posting.

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.

Note only is it a little more restrictive concerning the differences, than the Wikipedia text, but is also worth being explicitly mentioned, given the fact Mark Zbikowski himself - which gives a huge credibility bonus IMHO.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.