【问题标题】:Official MS reference for cmd.exe %errorlevel% 9009cmd.exe %errorlevel% 9009 的官方 MS 参考
【发布时间】:2014-04-15 18:45:28
【问题描述】:

所以我根据经验知道从 cmd.exe 运行有效程序并检查 %errorlevel% 将返回 0:

C:\>dir logo.bmp
 Volume in drive C has no label.
 Volume Serial Number is 5283-A7A2

 Directory of C:\

05/22/2008  12:43 PM         1,440,054 logo.bmp
               1 File(s)      1,440,054 bytes
               0 Dir(s)  71,723,995,136 bytes free

C:\>echo %errorlevel%
0

同样,尝试执行一个不存在的命令然后检查 %errorcode% 会给我一个 9009:

C:\>idontexist.exe
'idontexist.exe' is not recognized as an internal or external command,
operable program or batch file.

C:\>echo %errorlevel%
9009

多年来我一直在编写批处理脚本,而且它们一直都是这样工作的。但是,有人询问了有关该技术的兼容性(向前和向后)的问题,我找不到任何来自 Microsoft 的官方文档实际上将 9009 定义为找不到文件或程序时的错误级别。我最接近的是这个站点 (http://msdn.microsoft.com/en-us/library/ms681381(v=vs.85).aspx),不幸的是,它将 9009 列为 DNS 错误。

有谁知道微软在哪里记录了这种行为?

【问题讨论】:

  • 这里有一个非 MS 参考:en.kioskea.net/faq/2347-error-codes-in-windows。就兼容性而言,批处理文件不会很快消失。
  • DNS_ERROR 是 SystemErrorCode 9009 Errorlevel(或 ExitCode) 9009 是“不被识别为内部或外部命令”。虽然在一些微软论坛中提到(例如social.msdn.microsoft.com/Forums),但我也很惊讶,我似乎无法找到任何“官方”列表。
  • @EBGreen 是的,我也发现了非 MS 引用,甚至它缺少 9009“不被识别为内部或外部命令”代码。我同意你的观点,批处理文件不会去任何地方,但不幸的是,如果我想在我的脚本中使用它,我需要提供对这个特定错误代码的官方 MS 文档的引用。
  • 我怀疑它是否已被正式记录,尽管您可能会很幸运。但是应该注意的是,没有什么可以阻止任何特定的应用程序返回退出代码 9009 并且意味着完全不同的东西,因此将 9009 视为特殊情况可能是不明智的。
  • @HarryJohnston 这是一个很好的观点,适当地指出。

标签: batch-file cmd errorlevel


【解决方案1】:

Microsoft 有一个Common Error Lookup Tool 可以为您翻译错误代码(包括 HRESULT,这很方便)。 9009 的输出是:

# for decimal 9009 / hex 0x2331 :
  MSG_DIR_BAD_COMMAND_OR_FILE                                   cmdmsg.h       
# '%1' is not recognized as an internal or external command,
# operable program or batch file.
  SQL_9009_severity_10                                          sql_err        
# Cannot shrink log file %d (%s) because of minimum log space
# required.
  DNS_ERROR_RCODE_NOTAUTH                                       winerror.h     
# DNS server not authoritative for zone.
# for hex 0x9009 / decimal 36873 :
  SSLEVENT_NO_CIPHERS_SUPPORTED                                 lsapmsgs.mc    
# No suitable default server credential exists on this
# system. This will prevent
# server applications that expect to make use of the system
# default credentials
# from accepting SSL connections. An example of such an
# application is the directory
# server. Applications that manage their own credentials,
# such as the internet
# information server, are not affected by this.
# 4 matches found for "9009"

...所以您要查找的内容来自 cmdmsg.h。

它本身并不是真正的文档,但它至少是官方的。

【讨论】:

  • 它直接来自微软,所以在这个意义上它是“官方的”,会做我需要的。我已经忘记了在封闭源代码系统中查找信息是多么困难——多年来使用开源代码已经宠坏了我。再次感谢!
  • web page for error codes。答案中的页面已不存在。
  • 谢谢@DaisukeAramaki!我已更新答案以更正链接。
猜你喜欢
  • 2010-12-09
  • 1970-01-01
  • 1970-01-01
  • 2016-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-23
相关资源
最近更新 更多