通过 Windows 上的命令设置的错误级别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2140640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:49:22  来源:igfitidea点击:

Errorlevels set by commands on Windows

windowsbatch-filecmderrorlevel

提问by Santhosh

I have a batch program that calls several child batch programs and they make extensive use of various Windows commands. In case of error, I would like to provide logging information about the error details to the user.

我有一个批处理程序,它调用多个子批处理程序,它们广泛使用各种 Windows 命令。如果出现错误,我想向用户提供有关错误详细信息的日志信息。

How do I know what are the various error codes (a number in the range 0 to 256) that these commands can return and what are their interpretations in English?

我如何知道这些命令可以返回的各种错误代码(0 到 256 范围内的数字)是什么以及它们的英文解释是什么?

回答by Joey

If you really are on DOS (which I highly doubt) then the only way is

如果你真的在 DOS 上(我非常怀疑)那么唯一的方法是

command
if errorlevel 255 echo 255
if errorlevel 254 echo 254
if errorlevel 253 echo 253
...
if errorlevel 1 echo 1
if errorlevel 0 echo 0

The interpretations in a natural language are then up to you, as you should know what exactly you did try there.

自然语言的解释取决于你,因为你应该知道你在那里做了什么。

Note that on Windows you can usually just do

请注意,在 Windows 上,您通常可以这样做

command
echo %errorlevel%