I'm building a simple installer with NSIS, and would like to run it in Silent mode inside a batch script, where in the end I would check the ERRORLEVEL like that:
REM a simple test
REM get into folder and run the installer
cd /d my_installer_path
my_installer_made_with_nsis.exe /S
if %ERRORLEVEL% NEQ 0 echo something has gone wrong
Now, it seems that my_installer_made_with_nsis.exe always returns %ERRORLEVEL% 0 , even when inside the nsi code I explicitly set an error level and exit with Abort.
In my nsi script I use an ErrorHandling function like that
Function ErrorHandler
IfSilent +2 0
MessageBox MB_ICONSTOP "$err_msg"
DetailPrint "$err_msg"
SetErrorlevel 5 ; <---- APPARENTLY DOES NOT WORK
Abort
FunctionEnd
Then, in my code I call the errorhandler like that:
...
StrCpy $err_msg "An exception occurred: blah blah"
Call ErrorHandler
I would expect outside in the cmd shell that %ERRORLEVEL% was 5, but it is always 0.
Maybe I got wrong the whole concept of ErrorLevel in NSIS, but in that case is there a way to retrieve from the command shell the exit code of my installer?