Windows/cmd.exe与Linux/bash的$等价是什么?-程序退出/返回码? [英] What is the Windows/cmd.exe equivalent of Linux/bash's $? -- the program exit/return code?

查看:63
本文介绍了Windows/cmd.exe与Linux/bash的$等价是什么?-程序退出/返回码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何获取该应用程序从Windows命令行退出代码?

在Unix/bash中,我可以简单地说:

$ echo $?

从交互式和非交互式shell中找出程序的返回/退出代码.

现在,如何在Windows/cmd.exe中执行等效操作?

解决方案

使用错误级别",如下所示:

 如果错误级别1转到错误 

errorlevel命令有点特殊;如果返回码等于或高于指定的错误级别,则返回true.您也可以写

  IF%ERRORLEVEL%NEQ 0转到错误 

此页面很好地概述了如何在.bat文件中使用错误级别.

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?

解决方案

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.

这篇关于Windows/cmd.exe与Linux/bash的$等价是什么?-程序退出/返回码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆