从批处理文件中获取错误code [英] Get error code from within a batch file

查看:111
本文介绍了从批处理文件中获取错误code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行一对夫妇可执行文件的批处理文件,我希望它退出的成功,但如果停止出口code<?> 0,我如何做到这一点。

I have a batch file that runs a couple executables, and I want it to exit on success, but stop if the exit code <> 0. How do I do this?

推荐答案

听起来像是你会希望如果ERRORLEVEL命令。假设你的可执行文件失败时返回非0退出code,你做的是这样的:

Sounds like you'll want the "If Errorlevel" command. Assuming your executable returns a non-0 exit code on failure, you do something like:

myProgram.exe
if errorlevel 1 goto somethingbad
echo Success!
exit
:somethingbad
echo Something Bad Happened.

ERRORLEVEL进行检查,以更大,或相等检查,因此,任何非0的退出值将触发跳跃。因此,如果您需要检查一个以上特定的退出值,你应该检查一个最高优先。

Errorlevel checking is done as a greater-or-equal check, so any non-0 exit value will trigger the jump. Therefore, if you need to check for more than one specific exit value, you should check for the highest one first.

这篇关于从批处理文件中获取错误code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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