I have a scenario where a windows application that I execute in CI exits with -1073740791 eg Stack Overflow. One cmd, this can be caught obviously via %errorlevel% but on bash, at least this exit code maps to 127 in $?.
Obviously, bash on windows should not break scripting so anything above or beyond 0-255 is not fine.
Question is: Is there any special variables or mechanism directly in git-bash itself to catch this actual value ? In this case, the executable is testsuite (think off google benchhmark or google test) and exit code 127 - command not found is not helpful at all.
I had the same issue and i do not think that there is any way to do that within bash. I decided to wrap my executable in a powershell call, append the exit code to stdout and extract it afterwards like this:
OUTPUT=$(powershell ".\"$EXECUTABLE\" $PARAMETERS 2>&1 | % ToString; echo \$LASTEXITCODE")
# Save exit code to separate variable and remove it from $OUTPUT.
EXITCODE=$(echo "$OUTPUT" | tail -n1 | tr -d '\r\n')
OUTPUT=$(sed '$d' <<< "$OUTPUT")
Some notes:
| % ToString is for. Cmp. this SO Answer.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With