Windows batch files: .bat vs .cmd?

前端 未结 13 1731
傲寒
傲寒 2020-11-22 17:01

As I understand it, .bat is the old 16-bit naming convention, and .cmd is for 32-bit Windows, i.e., starting with NT. But I continue to see .bat fi

13条回答
  •  囚心锁ツ
    2020-11-22 17:34

    These answers are a bit too long and focused on interactive use. The important differences for scripting are:

    • .cmd prevents inadvertent execution on non-NT systems.
    • .cmd enables built-in commands to change Errorlevel to 0 on success.

    Not that exciting, eh?

    There used to be a number of additional features enabled in .cmd files, called Command Extensions. However, they are now enabled by default for both .bat and .cmd files under Windows 2000 and later.

    Bottom line: in 2012 and beyond, I recommend using .cmd exclusively.

提交回复
热议问题