batch-file - cmd.exe %errorlevel% 9009 的官方 MS 引用

标签 batch-file cmd errorlevel

所以我从经验中知道从 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 错误。

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

最佳答案

微软有一个 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。
它本身并不是真正的文档,但至少是官方的。

关于batch-file - cmd.exe %errorlevel% 9009 的官方 MS 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23091906/

相关文章:

windows - 使用批处理文件自动化 Windows 命令行实用程序 - 在实用程序启动后将击键发送到标准输入

python - 从 Windows 批处理执行 Python 脚本时相对路径中断?

Python 2 原始输入(): EOFError when reading a line in WINDOWS 7 command prompt

cmd - findstr 退出代码/错误级别

batch-file - 变量名中的字符转义

java - ProcessBuilder 找不到文件?!

powershell - 脚本执行后终止PowerShell进程

python - 在 python 中运行 cmd

batch-file - 使用ERRORLEVEL循环多次尝试批处理文件FTP进行密码/身份验证

scripting - 从plink获取返回码?