Build-wrapper does not properly return error code of child script

Template for a good bug report, formatted with Markdown:

  • versions used

    • build-wrapper, version 6.11 (win-x86-64)
  • ERRORLEVEL value of child script is not properly returned in following scenario:

    1. failure happens into an if / else condition
    2. script execution has moved into another folder (cd or pushd)
    3. exit is called with /b option (Exit - Terminate a script - Windows CMD - SS64.com)
  • steps to reproduce

@echo off
if "%1" == "ifexitnob" (
    echo into if, exit without /b
    pushd subfolder
    exit 1
    popd
)
if "%1" == "ifexitb" (
    echo into if, exit /b
    pushd subfolder
    exit /b 1
    popd
)

put above script into a script.bat file, then call it from build-wrapper and print ERRORLEVEL.

build-wrapper-win-x86-64.exe --out-dir test script.bat ifexitnob
echo %ERRORLEVEL% --> Will show 1, OK

build-wrapper-win-x86-64.exe --out-dir test script.bat ifexitb
echo %ERRORLEVEL% --> Will show 0, KO
  • potential workaround
    Do not use /b option of exit command, although it is common practice for Windows Batch scripting

Hi @scm_invn ,

I’ve tried what you posted and it seems to work:

C:\cfam>build-wrapper-win-x86\build-wrapper-win-x86-64.exe --out-dir cfam-out script.bat ifexitb
into if, exit /b

C:\cfam>echo %ERRORLEVEL%
1

what version of the build-wrapper are you using? Could you please share the build-wrapper output dir that you named test? We had this bug and it has been fixed 4 years ago, see CPP-1372.

Sure, version of BW is 6.11.
See attached output files, nothing relevant.
testnob_build-wrapper.log (966 Bytes)
testb_build-wrapper.log (962 Bytes)

@echo off
mkdir subfolder 2> nul
pushd subfolder
if "%1" == "ifexitb" (
    echo into if, exit /b
    exit /b 1
    popd
)
if "%1" == "ifexitnob" (
    echo into if, exit without /b
    exit 1
    popd
)

Issue seems related to underlying cmd.exe call strange behavior.
Probably above script can replicate the issue on your side.
If it is the case, try removing the popd statement at line 7, and now it works fine…

C:\WINDOWS\system32\cmd.exe /c script.bat ifexitnob
echo %ERRORLEVEL% --> Will show 1, OK

C:\WINDOWS\system32\cmd.exe /c script.bat ifexitb
echo %ERRORLEVEL% --> Will show 0, KO

So it is probably not a build-wrapper issue

Edit: not reproducible on all our machines, so this is not an issue to spend much time on. Just applying the workaround.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.