(imported topic written by SystemAdmin)
I spent hours trying to figure out how to use the new (in 8.0), and poorly documented, feature of evaluating the errorlevel (exit code) of a command to determine if my script was successful or not. I tried everything I found in the forums and on the knowledge base which invariably looked something like the code below, and always generated a “relevance substitution error”.
if
{exit code of action != 0
} exit 123 endif
I finally found a method that worked, and I thought I would share it.
I do most of my script development in AutoIT, and it is very easy to terminate and set the errorlevel on a script error, however it didn’t do much good if BigFix would just ignore it. So here is how I forced my task to fail on any errorlevel other than 0:
. . .
// execute the installer silently wait __Download\setup.exe /silent
// table of defined exit codes:
// 0 - setup successful
// 1 - application currently in use
// 2 - setup failed to create target directory
// 3 - setup failed to set target directory permissions
// 4 - setup failed to copy files into targed directory
// 5 - setup failed to update registry
continue
if
{exit code of action = 0
}
I have yet to try putting the “continue if {exit code of action = 0}” in the middle of a action, however it would certainly be worth trying if you needed to evaluate the output of more than one command.
I hope this saves someone the hours of headache I went through!
(imported comment written by MattBoyd)
Glad you figured out a way to use it. It would be great if you could set the result to those status messages in the console somehow instead of ‘Failed’. Feature request?
Also, I think something like this would stop the task, but I haven’t tried it:
if {exit code of action = 0}
waithidden thisexecutabledoesnotexistsoitthrowsanerror.exe
endif
(imported comment written by SystemAdmin)
+1 to Boyd’s feature request.
The next logical step would be to attempt remediation and/or alerting action for non-zero exit codes. For example, re-run the action, send a message, or fix the specific constraint causing it to fail then re-running.
(imported comment written by SystemAdmin)
boyd
Also, I think something like this would stop the task, but I haven’t tried it:
if {exit code of action = 0}
waithidden thisexecutabledoesnotexistsoitthrowsanerror.exe
endif
It does work, by itself anyway, however when I was developing a fixlet that downloaded and executed a custom installer, I always got the relevance substitution error on the {exit code of action != 0}. This was also reported by another user: http://forum.bigfix.com/viewtopic.php?id=6282
I did test and discover that you CAN do multiple {exit code of action} substitutions, however this may not be possible in all cases (such as the one described in the linked thread above). But this worked as expected and failed on the third continue if statement:
wait cmd /c dir c:\
continue
if
{exit code of action = 0
} wait cmd /c dir c:\
continue
if
{exit code of action = 0
} wait cmd /c dir c:\blah
continue
if
{exit code of action = 0
} wait cmd /c dir c:\
continue
if
{exit code of action = 0
}
Anyway… ‘continue if’ does work better in some circumstances than the if… endif statements that are described in some other threads.
(imported comment written by MattBoyd)
jfry, I’m not saying you’re wrong, but I think you have a typo in your relevance there (ation instead of action).
(imported comment written by SystemAdmin)
LOL… so I do.
Ok… I will edit my post so I don’t confuse anyone.