我想获得与 bash set -e
提供的相同的功能但在 Windows 批处理文件中。这怎么可能?
目前这允许我退出,但我不想在批处理文件的每一行之后添加这一行。
IF %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
最佳答案
以供引用
-e errexit
Exit immediately if a simple command exits with a non-zero
status, unless the command that fails is part of an until or
while loop, part of an if statement, part of a && or || list,
or if the command's return status is being inverted using !.
http://ss64.com/bash/set.html不幸的是,仅使用一个命令是不可能的。
您必须在 之后添加支票每个命令 你想在出错时退出。您可以使用或检查
||
而不是整个单独的行在命令结果上。command || exit /b
这也可以通过将其放在开头的变量中来简化。set "e=|| exit /b"
command1 %e%
command2 %e%
关于batch-file - bash 的 set -e 的 cmd.exe 替代品是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17898688/