Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What's the difference between a *.cmd and *.bat file?

Posted on 2006-06-24
12
Medium Priority
?
3,177 Views
Last Modified: 2013-11-18
What's the difference between a *.cmd and *.bat file?

Can *.cmd files be used in all versions of windows?
Can it be used in MS-DOS?
0
Comment
Question by:Axter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 30

Expert Comment

by:callrs
ID: 16974987
http://commandwindows.com/batch.htm     The Command Line in Windows XP: Batch files
"The CMD extension is limited to newer Windows systems and is not recognized in Windows 9x/Me systems. In Windows XP, there is little practical difference between the two extensions"
0
 
LVL 30

Author Comment

by:Axter
ID: 16975117
>>there is little practical difference between the two extensions"

My main question is, what is the difference?
0
 
LVL 30

Expert Comment

by:callrs
ID: 16975177
http://filext.com/detaillist.php?extdetail=CMD    http://filext.com/detaillist.php?extdetail=BAT

Like naming a text file as ".txt" or ".log" -- helps to catalog / search / use files, though the contents are the same type.

Examples to illustrate:

http://www.windowsitpro.com/Windows/Article/ArticleID/21110/21110.html     BAT vs. CMD
"To prevent problems, when I write batch files that contain no portions that will fail under Win9x, I name the file with a .bat extension, which will run under any Windows version. If I use features that only Win2K and NT support, I name the file with a .cmd extension. Win2K and NT recognize .cmd files as executable and will run them. Win9x doesn't recognize .cmd as an executable file type: If you attempt to run a file with a .cmd extension under Win9x, the OS simply reports a Bad command or file name error message, and no damage is done."

http://www.windowsitpro.com/Windows/Article/ArticleID/24048/24048.html     Alternative to BAT vs. CMD
"In Reader to Reader: "BAT vs. CMD" (July 2001, InstantDoc ID 21110), Chris Taylor recommends naming batch files with a .bat or .cmd extension depending on whether the files will run in Windows 9x (.bat) or Windows 2000 or Windows NT (.cmd). You can also use the .cmd extension for Windows XP. I prefer to use the following code in my batch files to determine the underlying OS and branch to the appropriate sections of code:
If "%OS%" == "Windows_NT" goto winnt
If NOT "%WINBOOTDIR%" == "" goto win95
If you use this method, remember to make :winnt and :win95 portions in your script. Also, you need to create an :end portion and use the Goto command to send both sections there. Otherwise, you might run both sections on one of the two platforms.      —Dave Russell  dave3579@hotmail.com"
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Assisted Solution

by:venom96737
venom96737 earned 400 total points
ID: 16975264
The main difference is that a .bat is actually treated as a command file BUT it has to be interpreted by command.com.  they are used in such a way that it is literally like the computer typing commands to itself such as changing a directory cd\blah blah and runing a file can be automated so you dont have to type it everytime want to run a program you can just run the batch file.
0
 
LVL 30

Author Comment

by:Axter
ID: 16975282
venom96737,
>>The main difference is that a .bat is actually treated as a command file BUT it has to be interpreted by command.com.  

You didn't describe a difference.  You just described what a bat file does.

What I want to know is what is the difference between them.
0
 
LVL 30

Author Comment

by:Axter
ID: 16975291
I've been using DOS since the late 80's, so I'm very familiar with what is a bat file.

I'm not looking for an explanation about what is a bat file.

I'm looking for DETAILS on what is the difference between a bat file and a cmd file.

And I don't think it's just the name difference.  I find it hard to believe that MS would come up with a new extension for no apparent good reason.
0
 
LVL 30

Expert Comment

by:callrs
ID: 16975364
>I find it hard to believe
I find it hard to believe that people actually prefer Windows over Linux. LOL
I find it hard to believe that MS gives us annoyingly non-re-sizable system windows
I find it hard to believe that Notepad has only one undo buffer
I find it hard to believe to believe that Windows Explorer uses the same favorites list as Internet Explorer
I find it hard to believe....

: )

But, for this issue, it helps to have more options for file names. It DOES help categorize files, just as sub-folders help in organizing files.
In Win XP, to get to command prompt, we do Start -> Run -> cmd
In Win 98, we do Start -> Run -> Command
So, it appears MS likes   the name "cmd" for for XP.
0
 
LVL 18

Expert Comment

by:carl_legere
ID: 16975374
It all dates back to 1996 when nt4 and win98 were out at the same time.  Microsoft always strives to sell the difference between a server and a workstation, which coming from the commerical UNIX world, I've always found to be suspect.

 I'm sure you are aware that 9x comes with command.com for parsing dos commands, batches, etc.  I'm sure you are aware that nt/2000/2003/xp/newer have ain improved command interpreter, cmd.exe.

dothis.cmd is going to be interpreted only by cmd.exe and will be incompatible with 9x operating systems.

iif your script is named dothis.cmd it is your way of telling the computer to run it with the 32bit command interpreter, cmd.exe  

Since windows tries it's very hardest to be backward compatible, they include support for dothis.bat. which is also run via cmd.exe
0
 
LVL 30

Expert Comment

by:callrs
ID: 16975427
That's very nicely said carl. Thanks  :)  Expands on my 2nd post here, which I should have put into my own words.

Give carl 60% and me 40% lol

0
 
LVL 70

Expert Comment

by:Merete
ID: 16978275
Command line interpreter
http://en.wikipedia.org/wiki/CMD_file_%28CP/M%29
http://en.wikipedia.org/wiki/Command_line_interpreter
cmd.exe; the command line interpreter for OS/2 and Windows NT-based operating systems, or the CMD files which this interpreter uses
The CMD file; an executable format used by CP/M-86.

Batch file
http://en.wikipedia.org/wiki/BAT_file
In DOS, OS/2 and Windows, a batch file is a text file containing a series of commands intended to be executed by the command interpreter. When a batch file is run, the shell program (usually command.com or cmd.exe) reads the file and executes its commands, normally line-by-line. A batch file is analogous to a shell script in Unix-like operating systems.

DOS batch files have the filename extension .BAT. Batch files for other environments may have different extensions, e.g. .CMD in Windows NT and OS/2, or .BTM in 4DOS and related shells.

AUTOEXEC.BAT is a special batch file that is executed during the booting process.


0
 
LVL 30

Author Comment

by:Axter
ID: 16978402
Merete,
As I already stated, I'm not interested in the diffinition or description of a bat file.

What I am interested in, is to know what is the difference between using a *.cmd file and a *.bat file.
The above comment doesn't help me in answering my question.

If no one can give me a description of the difference, then I will have to assume that callrs is right, in that there is no difference other then what OS a *.cmd file can be used in.
And I'll award points to callrs and carl_legere.
0
 
LVL 30

Accepted Solution

by:
callrs earned 1600 total points
ID: 16978805
In the context of Windows batch files: cmd and bat are both text files -- not binary
cmd:  Win2K/XP, not 9x, batch files run by a program called "cmd"
bat:  win2K/XP/9x batch files run both by "cmd" & the lesser-capable "command"

Difference:

- cmd files (can) contain commands that 9x won't recognize. So instantly you know that the file WONT work on 9x.
- bat files can contain both 9x & NT commands, so instantly you think "What the heck? Do i have to open the darn thing to know if it will run on 9x?"

So to make it easy to catalogue which file is for which OS, "Chris Taylor recommends naming batch files with a .bat or .cmd extension depending on whether the files will run in Windows 9x (.bat) or Windows 2000 or Windows NT (.cmd). "
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question