cmd.exe %errorlevel% 9009的官方MS参考资料

17

我有经验知道从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

我已经写了多年的批处理脚本,它们一直以这种方式工作。然而,有人问到这种技术的兼容性(向前和向后),我找不到微软的任何官方文档,实际上定义9009为未找到文件或程序时的错误级别。我找到的最接近的是这个网站 (http://msdn.microsoft.com/en-us/library/ms681381(v=vs.85).aspx),不幸的是,它将9009列为DNS错误。

有人知道微软在哪里记录这种行为吗?


这里有一个非微软的参考链接: http://en.kioskea.net/faq/2347-error-codes-in-windows。就兼容性而言,批处理文件在短期或长期内都不会消失。 - EBGreen
DNS_ERROR-thing 是 SystemErrorCode 9009Errorlevel(或 ExitCode)9009 表示“未被识别为内部或外部命令”。虽然在一些微软论坛中提到过(例如 http://social.msdn.microsoft.com/Forums),但我也很惊讶,似乎找不到任何“官方”列表。 - Stephan
@EBGreen 是的,我也找到了非微软的参考资料,即使它缺少了9009 "未被识别为内部或外部命令" 的代码。我同意你的看法,批处理文件不会消失,但不幸的是,如果我想在我的脚本中使用它,我需要提供对这个特定错误代码的官方MS文档的引用。 - AWT
2
我怀疑这并没有正式记录,但你可能会有好运气。但需要注意的是,并没有什么阻止特定应用程序返回退出代码9009并意味着完全不同的含义,因此将9009视为特殊情况可能并不明智。 - Harry Johnston
@HarryJohnston 这是一个很好的观点,已经注意到了。 - AWT
1个回答

20

微软有一个通用错误查询工具,可以为您翻译错误代码(包括实用的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。

这不算是真正的文档,但至少是官方的。


4
这是直接来自微软,所以在这个意义上它是“官方”的,能够满足我的需求。我已经忘记了在闭源系统中查找信息有多么困难——长年使用开源系统让我变得挑剔了。再次感谢! - AWT
1
错误代码的网页(https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes?redirectedfrom=MSDN)。该答案中的页面已不存在。 - Daisuke Aramaki
1
谢谢,@DaisukeAramaki!我已经更新了答案以更正链接。 - Mark

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接