windowscygwinexit-codeerrorlevelmintty

How do I get exit code of script run with mintty.exe?


In Windows, I'm excecuting a bash script using Cygwin64 and mintty.exe, this way:

mintty.exe -e C:\some_path\some_bash_script.sh

I need to capture the script's errors but %ERRORLOVEL% is always 0, even when the script fails.

How can I get the exit code of the bash script, when executed this way?


Solution

  • mintty does not return any error code, what you can do is :

    mintty.exe -e bash -c "C:\some_path\some_bash_script.sh; echo $? > /c/temp/return-code"
    

    and test the content of C:\temp\return-code