一个批处理文件可以捕获它被调用命令的退出codeS? [英] Can a batch file capture the exit codes of the commands it is invoking?

查看:114
本文介绍了一个批处理文件可以捕获它被调用命令的退出codeS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,让我们说,我有一个要求,退出code myapp1.exe和myapp1.exe退出1.可以批处理文件捕获这一信息,要么强制批处理文件相同退出退出一个批处理文件code或执行一些其他逻辑?


解决方案

 关闭@echo
REM ...
设置错误级别=
MyApp1.exe
退出/ B%ERRORLEVEL%

将是明确的变体。

Basically, let's say that I have a batch file that calls myapp1.exe and myapp1.exe exits with Exit Code 1. Can the batch file capture this information and either force the batch file to exit with that same exit code or perform some other logic?

解决方案

@echo off
rem ...
set errorlevel=
MyApp1.exe
exit /b %errorlevel%

would be the explicit variant.

这篇关于一个批处理文件可以捕获它被调用命令的退出codeS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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