How do I get the application exit code from a Windows command line?

后端 未结 7 744
执笔经年
执笔经年 2020-11-22 02:13

I am running a program and want to see what its return code is (since it returns different codes based on different errors).

I know in Bash I can do this by running<

7条回答
  •  温柔的废话
    2020-11-22 02:45

    It's worth noting that .BAT and .CMD files operate differently.

    Reading https://ss64.com/nt/errorlevel.html it notes the following:

    There is a key difference between the way .CMD and .BAT batch files set errorlevels:

    An old .BAT batch script running the 'new' internal commands: APPEND, ASSOC, PATH, PROMPT, FTYPE and SET will only set ERRORLEVEL if an error occurs. So if you have two commands in the batch script and the first fails, the ERRORLEVEL will remain set even after the second command succeeds.

    This can make debugging a problem BAT script more difficult, a CMD batch script is more consistent and will set ERRORLEVEL after every command that you run [source].

    This was causing me no end of grief as I was executing successive commands, but the ERRORLEVEL would remain unchanged even in the event of a failure.

提交回复
热议问题