Windows 批处理文件:.bat 还是 .cmd? [英] Windows batch files: .bat vs .cmd?

查看:39
本文介绍了Windows 批处理文件:.bat 还是 .cmd?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,.bat 是旧的 16 位命名约定,而 .cmd 用于 32 位 Windows,即从 NT 开始.但是我继续在任何地方看到 .bat 文件,并且它们似乎使用任一后缀都完全相同.假设我的代码永远不需要在比 NT 旧的任何东西上运行,那么我命名我的批处理文件的方式真的很重要,或者是否有一些问题在等待我使用错误的后缀?

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?

推荐答案

来自 这个新闻组发布,由Mark Zbikowski 本人发布:

From this news group posting by Mark Zbikowski himself:

就 CMD.EXE 而言,.CMD 和 .BAT 之间的区别是:启用扩展后,.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.

换句话说,如果 ERRORLEVEL 设置为非 0,然后您运行这些命令之一,则结果 ERRORLEVEL 将是:

In other words, if ERRORLEVEL is set to non-0 and then you run one of those commands, the resulting ERRORLEVEL will be:

  • 在 .bat 文件中保留其非 0 值
  • 在 .cmd 文件中重置为 0.

这篇关于Windows 批处理文件:.bat 还是 .cmd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆