Exiting batch with `EXIT /B X` where X>=1 acts as if command completed successfully when using && or || operators between batch calls

前端 未结 4 719
借酒劲吻你
借酒劲吻你 2020-12-09 04:26

I\'m trying to chain a series of .bat files using the EXIT /B X command to return success or failure and && and || for conditi

4条回答
  •  醉梦人生
    2020-12-09 04:55

    If you ask me, exit codes in batch files are broken for this exact reason, but there is a hacky workaround you can use. As the last line of your batch file, use:

    @%COMSPEC% /C exit 1 >nul
    

    Since this is an actual process that is started you get a real process exit code and && and || will work.

提交回复
热议问题