我有经验知道从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错误。
有人知道微软在哪里记录这种行为吗?
SystemErrorCode 9009
。Errorlevel
(或ExitCode
)9009 表示“未被识别为内部或外部命令”。虽然在一些微软论坛中提到过(例如 http://social.msdn.microsoft.com/Forums),但我也很惊讶,似乎找不到任何“官方”列表。 - Stephan