Can a batch file capture the exit codes of the commands it is invoking?

前端 未结 4 1461
刺人心
刺人心 2021-02-12 08:34

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 batc

4条回答
  •  梦如初夏
    2021-02-12 09:07

    The accepted answer is correct, but if you are using call to call another batch script, and that second batch script is using SetLocal, you may need to use a parsing trick to accomplish this. If you are running into this, add the following code before your exit b:

    ENDLOCAL&set myvariable=%myvariable%
    

    Now the value of myvariable is made available to the calling context and you can see the value in the other script.

    References:
    https://stackoverflow.com/a/16167938/89590
    http://www.borngeek.com/2008/05/22/exiting-batch-file-contexts/

提交回复
热议问题