gpt4 book ai didi

Windows 批处理文件 : . bat vs .cmd?

转载 作者:可可西里 更新时间:2023-11-01 11:50:40 26 4
gpt4 key购买 nike

据我了解,.bat 是旧的 16 位命名约定,而 .cmd 适用于 32 位 Windows,即以 NT 开头。但我继续看到 .bat 文件无处不在,它们似乎使用任一后缀都完全相同。假设我的代码永远不需要在 NT 之前的任何版本上运行,那么我命名我的批处理文件的方式真的很重要吗,或者是否有一些陷阱在等待我使用错误的后缀?

最佳答案

来自 this news group posting通过 Mark Zbikowski他自己:

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 将是:

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

关于Windows 批处理文件 : . bat vs .cmd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/148968/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com