Archive: ErrorLevel Not returning


ErrorLevel Not returning
  I am using a custom errorlevel in an installer and it does not appear to be returning as necessary...

     !insertmacro logme $INSTLOG "OS Detected: Windows $R0 $R1" l

!insertmacro logme $INSTLOG "Install Error: OS Not Supported" l
MessageBox MB_OK
|MB_ICONINFORMATION "Please provide the following information to support.$\r$\n$\r$\nInstallation of ${APP_DESC} failed with error: OS Not Supported$\r$\n$\r$\nTerminating Installation" /SD IDOK
SetErrorLevel 999
SetRebootFlag false
goto _ierrored
>

    _ierrored:


!
insertmacro logme $INSTLOG "Cleaning Up Temporary Files ... Please be Patient" b
SetOutPath $INSTDIR
!insertmacro RemoveFilesAndSubDirs "$INSTDIR\${APP_NAME}"
RMDir /r "$INSTDIR\${APP_NAME}"

!insertmacro logme $INSTLOG "*** ${APP_DESC} Installation Ended in Error ***" b
StrCpy $FINISHPAGE_TEXT "The installation of ${APP_DESC} has resulted in an error and was not completed.$\r$\n$\r$\nClick Finish to close this wizard."

_end:
There are just the two sections of any relavence so you can see whats taking place.. The log is generating correctly, but there errorlevel does not appear to be getting set.

13.06.2010 12:28:47 *-----------------------------------------------------*
13.06.2010 12:28:47 ### Microsoft Windows Installer 4.5 Installation Starting
13.06.2010 12:28:47 ### Build Verison: 1.0.0.1
13.06.2010 12:28:47 ### Runtime: 6/13/2010 12:28:47
13.06.2010 12:28:47 ### Switches: /S
13.06.2010 12:28:47 *-----------------------------------------------------*
13.06.2010 12:28:47
13.06.2010 12:28:47 Silent Installation has been Requested
13.06.2010 12:28:47 Running Pre-installation Processes
13.06.2010 12:28:47 Detecting the Running Operating System
13.06.2010 12:28:47 OS Detected: Windows 7 64
13.06.2010 12:28:47 Install Error: OS Not Supported
13.06.2010 12:28:47 Cleaning Up Temporary Files ... Please be Patient
13.06.2010 12:28:47 *** Microsoft Windows Installer 4.5 Installation Ended in Error ***

Any Ideas are greatly appreciated..

Thanks...

I don't see Quit in there


Do you have to have a Quit in order for it to return the errorlevel... I thought the SetErrorLevel was enough for it to assign the errorlevel for when the installation finishes..? Please correct me if I am wrong.

In a commandline window I do the following...

>Set errorlevel=15 ; Set a dummy errorlevel level to validate it changes
>Installer.exe /S
>echo %errorlevel% ; Still returns 15 for the errorlevel, like the installer NEVER influenses it..


Just as a FYI, I tested with the Quit in there, and it is STILL not returning the errorlevel correctly. Not sure what is up...

I have also tested different methods of SetErrorLevel for ex.
SetErrorLevel "999"
SetErrorLevel 999
SetErrorLevel '999'

All with the same result, none of them return...


I believe SetErrorLevel must come immediately before your Quit command (not too sure if GoTo's are allowed), as otherwise NSIS' own code for error level setting upon installer exit may override whatever you set.
Worth a try, at least - our installers have it set immediately before Quit / last command of .onGuiEnd , and work correctly.


It looks like you have masked the true errorlevel by setting a variable with that name before the program started. Remove the "Set ErrorLevel=15" and see if your program returns 999.


That does not mask it, anytime the NSIS installer finishes it should overwrite the previous errorlevel... I have even created small scripts based on some recommendations from the others...

Doesn't Work: Post Execution Errorlevel = 0


Name "SetErrorLevel test"


>OutFile "SetErrorLevel.exe"

>Function .onInit
FunctionEnd

Section
SetErrorLevel 25
SectionEnd
>
Doesn't Work: Post Execution Errorlevel = 0

Name "SetErrorLevel test"


>OutFile "SetErrorLevel.exe"

>Function .onInit
FunctionEnd

Section
SectionEnd

>Function .onGUIEnd
SetErrorlevel 25
Quit
FunctionEnd
>
No matter how you do it, for some reason the errorlevel is not returning... I have another installer where errorlevel is assigned with no problem the exact same way as in the first post, BUT it is not assigned manually, but by the installer... For ex.

ExecWait "blah blah blah" $0
SetErrorLevel $0

That works find with no problem... So not quite sure what is up... Im Stumped for the moment...

So, a little more into it.. And this is even a little more messed up...

From the scripts in my previous post. If you call it from command line as just seterrorlevel.exe it returns with 0. But if you call it from command line as cmd /c "seterrorlevel.exe" it actually does return the errorlevel of 25... Ugh... Now I am lost, if it is just an interfacing issue or if there is some underlying thing in my NSIS script that is not getting set...


To verify error levels, use another nsis script and call ExecWait yourapp.exe $0 and check the register, cmd.exe has many problems with error codes


Anders is right..
In cmd.exe, if you want to catch the correct ERRORLEVEL from a non-console app, you must call

start "" /WAIT myapp.exe
echo %ERRORLEVEL%

or make a program (like Anders is suggesting) that catch the errorlevel for you

errorlevel is not the same as %errorlevel%
  Raymond Chen wrote an article that explains ERRORLEVEL is not the same as %ERRORLEVEL%. That's why I suggested that your "Set errorlevel=0" and "echo %errorlevel% are not displaying the actual errorlevel that the exe returns.

You can also refer to the MS documentation of the "IF" command which says

%errorlevel% expands into a string representation of the current value of errorlevel, provided that there is not already an environment variable with the name ERRORLEVEL