Solved

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

Posted on 2006-06-24
12
3,158 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
12 Comments
 
LVL 30

Expert Comment

by:callrs
Comment Utility
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
Comment Utility
>>there is little practical difference between the two extensions"

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

Expert Comment

by:callrs
Comment Utility
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
 
LVL 15

Assisted Solution

by:venom96737
venom96737 earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 30

Expert Comment

by:callrs
Comment Utility
>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
Comment Utility
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
Comment Utility
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 69

Expert Comment

by:Merete
Comment Utility
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
Comment Utility
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 400 total points
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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 …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now