What is the Windows/cmd.exe equivalent of Linux/bash's $? — the program exit/return code? [duplicate]

与世无争的帅哥 提交于 2020-01-14 08:49:07

问题


Possible Duplicate:
How do I get the application exit code from a Windows command line?

In Unix/bash, I can simply say:

$ echo $?

to find out the return/exit code of a program, both from interactive and non-interactive shells.

Now, how can I do the equivalent in Windows/cmd.exe?


回答1:


Use "errorlevel", like this:

IF ERRORLEVEL 1 GOTO ERROR

The errorlevel command is a little peculiar; it returns true if the return code was equal to or higher than the specified errorlevel. You can also write

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

This page is a good overview of how to use errorlevels in .bat files.




回答2:


The equivalent is:

echo %ERRORLEVEL%



回答3:


check for the ERRORLEVEL



来源:https://stackoverflow.com/questions/277288/what-is-the-windows-cmd-exe-equivalent-of-linux-bashs-the-program-exit-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!