gpt4 book ai didi

batch-file - 命令失败时如何使批处理文件停止

转载 作者:行者123 更新时间:2023-12-05 04:12:37 25 4
gpt4 key购买 nike

如果第一个或任何其他命令失败,我如何创建一个批处理文件来停止运行其他/下一个命令。

call grails clean 
call grails compile
call grails package
call grails war

如果 grails clean 失败,则 grails compile 不应运行,与其他的一样。

最佳答案

ERRORLEVEL 环境变量保存最后执行命令的返回值。所以你可以使用:

IF %ERRORLEVEL% NEQ 0 (
echo "Previous command execution failed."
exit %ERRORLEVEL%
)

请参阅http://steve-jansen.github.io/guides/windows-batch-scripting/part-3-return-codes.html了解详情。

关于batch-file - 命令失败时如何使批处理文件停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40146746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com