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

    Question

  • 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

    What's new in Powershell 3.0 (Technet Wiki)

    Friday, February 17, 2012 7:45 AM

Answers

  • 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

    • Marked as answer by Bigteddy Friday, February 17, 2012 2:52 PM
    Friday, February 17, 2012 2:06 PM
  • 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. ;)

    • Marked as answer by Bigteddy Friday, February 17, 2012 8:14 AM
    Friday, February 17, 2012 8:10 AM
    • Marked as answer by Bigteddy Friday, February 17, 2012 2:52 PM
    Friday, February 17, 2012 1:32 PM

All replies

  • 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. ;)

    • Marked as answer by Bigteddy Friday, February 17, 2012 8:14 AM
    Friday, February 17, 2012 8:10 AM
    • Marked as answer by Bigteddy Friday, February 17, 2012 2:52 PM
    Friday, February 17, 2012 1:32 PM
  • 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

    • Marked as answer by Bigteddy Friday, February 17, 2012 2:52 PM
    Friday, February 17, 2012 2:06 PM
  • Thanks.  I think between the three responses, we just about covered it!

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Friday, February 17, 2012 2:52 PM
  • 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

    What's new in Powershell 3.0 (Technet Wiki)

    It is very clear that they are spelled differently.  This can be a problem for those that are "hard or spelling".

    ;)


    ¯\_(ツ)_/¯

    Friday, February 17, 2012 3:38 PM