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

    Întrebare

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

    17 februarie 2012 07:45

Răspunsuri

  • 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 Bigteddy 17 februarie 2012 14:52
    17 februarie 2012 14:06
  • 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 Bigteddy 17 februarie 2012 08:14
    17 februarie 2012 08:10
    • Marcat ca răspuns de Bigteddy 17 februarie 2012 14:52
    17 februarie 2012 13:32

Toate mesajele

  • 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 Bigteddy 17 februarie 2012 08:14
    17 februarie 2012 08:10
    • Marcat ca răspuns de Bigteddy 17 februarie 2012 14:52
    17 februarie 2012 13:32
  • 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 Bigteddy 17 februarie 2012 14:52
    17 februarie 2012 14:06
  • 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)

    17 februarie 2012 14:52
  • 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".

    ;)


    ¯\_(ツ)_/¯

    17 februarie 2012 15:38