How to properly report an exit status in batch?

后端 未结 5 1456
[愿得一人]
[愿得一人] 2020-12-03 13:08

I\'m facing a weird situation where a batch file I wrote reports an incorrect exit status. Here is a minimal sample that reproduces the problem:

bug.cmd

5条回答
  •  春和景丽
    2020-12-03 13:35

    The following is working ok invoking the bat with CALL:

    bug.bat:

    echo before
    
    if "" == "" (
            echo first if
            exit /b 1
    
            if "" == "" (
                    echo second if
            )
    )
    

    test.bat:

    call bug.bat
    echo Exit Code is %ERRORLEVEL%
    

    Exit Code is 1

提交回复
热议问题