heldain
23rd September 2011 11:59 UTC
Exit code on embedded installers
Bad topic title I know.
I'm running an installer from my NSIS installer/script via the following:
Section "app2" Section2
; Set Section properties
SetOverwrite on
SectionIn RO
;Set Section Files and Shortcuts
SetOutPath "$INSTDIR\Install\"
File "..\..\source\biginstaller\app2.exe"
ExecWait "$INSTDIR\Install\app2.exe"
SectionEnd
However I want to abort the whole script/installer if this installer fails to complete. I.e. if the exit code != 0.
I did find a 'Useful Script' that mentions this, but I'm being intellectually challenged and cant find how to apply it, as the example seems to omit this section.
http://nsis.sourceforge.net/Embedding_other_installers#Using_the_return_value_from_the_ExecWait
.
Suggestions please?
demiller9
23rd September 2011 13:18 UTC
There is an optional parameter to capture the exit code. The manual is your friend.
heldain
23rd September 2011 13:24 UTC
I saw that, however getting the exit code and handling it are different things. Its the handling that I'm struggling with.
LoRd_MuldeR
23rd September 2011 13:35 UTC
First of all you need to figure out what ExitCode the installer you run will return in for what situation.
This depends on the individual installer and may not be answered in general.
Then simply use a "StrCmp $1 <VAL> <GoIfEqual> <Otherwise>" to decide where to jump, depending on the ExitCode.
ExecWait '"$INSTDIR\Install\app2.exe"' $1
StrCmp $1 0 Success ; Jump to 'Success' if (and only if) ExitCode was '0'
MessageBox MB_OK "Failed to install. Setup will exit!"
Quit
Success:
MessageBox MB_OK "Installed correctly"
For more complex things, you may want to have a look at ${switch} from LogicLib.nsh ;)
MSG
23rd September 2011 13:38 UTC
Or, preferably, use the logiclib and do:
${If} $1 == "<VAL>"
;stuff
${Else}
;other stuff
${EndIf}
demiller9
23rd September 2011 13:38 UTC
Include LogicLib.nsh and then
ExecWait "$INSTDIR\Install\app2.exe" $0
${If} $0 <> 0
; app2 has failed, must cleanup and stop
...
${EndIf}
or
ExecWait "$INSTDIR\Install\app2.exe" $0
${If} $0 = 0
; app2 success, continue remaining operations
...
${EndIf}
(Edit: overlapping posts - MSG and I are suggesting the same thing.)
MSG
23rd September 2011 13:39 UTC
...wow, look at us being all helpful today. :P