What's the difference between a .cmd and a .bat file?
-
17 februarie 2012 07:45
Well, that's the question. I always call my batch files "name.cmd", because I'm not sure what would happen if I called it "name.bat". I assume it would still work, but what is the difference between the way Windows treats these two file extensions?
Or are they completely interchangeable, .bat being kept for backward-compatibility?
Grant Ward, a.k.a. Bigteddy
Toate mesajele
-
17 februarie 2012 08:10Moderator
As far as I know: ATM it has no effect what so ever. All current used Windows are based on NT "granfater" and can run .cmd code fine.
It had some effect when Win9x/ME line was still "alive" - .cmd would not run in command.com that was available on those platforms, so naming your script with .cmd extension would prevent you from ending up with lot of errors about wrong syntax/ command name.
Anyway: I like to name does files .cmd anyway, so that it obviuos what environment I'm pointing at. ;)
- Marcat ca răspuns de BigteddyMicrosoft Community Contributor 17 februarie 2012 08:14
-
17 februarie 2012 13:32
I found a couple of pretty good articles on the topic that seem to go into a little more detail:
http://stackoverflow.com/questions/148968/windows-batch-files-bat-vs-cmd
http://waynes-world-it.blogspot.com/2008/08/difference-between-bat-and-cmd.htmldifference-between-bat-and-cmd.html
- Marcat ca răspuns de BigteddyMicrosoft Community Contributor 17 februarie 2012 14:52
-
17 februarie 2012 14:06Moderator
As cited in the previous responses and the links provided, there is almost no 'practical' difference between the two. One other minor distinction, besides the ones already noted, is that the PATHEXT environment variable lists the .BAT extension before the .CMD extension in its list. This means that .BAT files take precedence over .CMD files when two versions of the same file name exist in the same folder. That is, a file named BATCH.BAT would be executed and not BATCH.CMD, if the name without the extension is used to invoke the procedure and both files existed in the addressed forlder. As I said, a minor difference, but it has bitten me on one or two occasions.Tom Lavedas
- Marcat ca răspuns de BigteddyMicrosoft Community Contributor 17 februarie 2012 14:52
-
17 februarie 2012 14:52Thanks. I think between the three responses, we just about covered it!
Grant Ward, a.k.a. Bigteddy
-
17 februarie 2012 15:38
Well, that's the question. I always call my batch files "name.cmd", because I'm not sure what would happen if I called it "name.bat". I assume it would still work, but what is the difference between the way Windows treats these two file extensions?
Or are they completely interchangeable, .bat being kept for backward-compatibility?
Grant Ward, a.k.a. Bigteddy
It is very clear that they are spelled differently. This can be a problem for those that are "hard or spelling".
;)
¯\_(ツ)_/¯