Windows批处理文件:.bat vs .cmd? [英] Windows batch files: .bat vs .cmd?
问题描述
根据我的理解, .bat
是旧的16位命名约定, .cmd
32位Windows,即从NT开始。但我继续看到.bat文件无处不在,他们似乎工作完全相同使用后缀。假设我的代码永远不需要运行NT以上的任何东西,真正重要的是什么方式我命名我的批处理文件,或者有一些 gotcha 等待我使用错误的后缀?
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 files everywhere, and they seem to work exactly the same using either suffix. Assuming that my code will never need to run on anything older than NT, does it really matter which way I name my batch files, or is there some gotcha awaiting me by using the wrong suffix?
推荐答案
从维基百科:
维基百科的新报价
之间.cmd
和.bat文件执行是在
.cmd文件中的ERRORLEVEL变量
即使成功的命令更改
受命令扩展影响
(当启用命令扩展时),
,而在.bat文件中,ERRORLEVEL
变量只有在错误时才更改。
The only known difference between .cmd and .bat file execution is that in a .cmd file the ERRORLEVEL variable changes even on a successful command that is affected by Command Extensions (when Command Extensions are enabled), whereas in .bat files the ERRORLEVEL variable changes only upon errors.
上面维基百科报价的来源实际上是基于此新闻组发布。
The source for the Wikipedia quote above is actually based on this news group posting.
。CMD和.BAT之间的区别,就CMD.EXE而言,是
是:启用扩展,.CMD
文件中的PATH / APPEND / PROMPT / SET / ASSOC将设置ERRORLEVEL,而不管错误。 .BAT只在错误时设置ERRORLEVEL
。
The differences between .CMD and .BAT as far as CMD.EXE is concerned are: With extensions enabled, PATH/APPEND/PROMPT/SET/ASSOC in .CMD files will set ERRORLEVEL regardless of error. .BAT sets ERRORLEVEL only on errors.
不仅对维基百科文本,但也值得明确提及,鉴于它是由 Mark Zbikowski 自己发布的事实 - 这给了一个巨大的可信度奖金IMHO。
Not only is it a little more restrictive concerning the differences, than the Wikipedia text, but is also worth being explicitly mentioned, given the fact it was posted by Mark Zbikowski himself - which gives a huge credibility bonus IMHO.
这篇关于Windows批处理文件:.bat vs .cmd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!