Exit codes of actions

(imported topic written by msmeltzer)

I have searched the forum and have not found any consistent answers.

Does using the {exit code of action} feature really work in 8.0+?

I have tried simple tests and am finding the exit code is always non-zero even though it really is 0. For example:

wait msiexec /i program.msi /qn

if {exit code of action != 0}

exit 123

endif

The installation succeeds, but the if statement is evaluating to true, so it tries to run the “exit 123” which fails to evaluate.

Client version is 8.2.1310.0

Thanks,

Marc

(imported comment written by jgstew)

I don’t have a lot of experience with using exit codes like this, but I have heard that they do not work well in the fixlet debugger if that is where you are testing it. Are you testing this through actions in the console?

Also, I’m wondering, what you are trying to accomplish with the exit codes? Are you just trying to determine if the software has installed or not? If so, you can achieve this with relevance instead.

See the last relevance here for an example:
http://bigfix.me/fixlet/details/3728

(imported comment written by msmeltzer)

Like every other post I’ve seen, I would like to perform a second action only if the first action completes successfully.

Yes, I’ve been testing this in the debugger, but before that, I tried deploying an action and it failed because of a relevance substitution error.

Your example links to Adobe Flash upgrade, which I don’t think was the right link, unless I’m missing something.

(imported comment written by jgstew)

The link to adobe flash was correct, I was referring to this relevance:

(
not

exists
keys
whose
(value
"DisplayName"

of

it

as
string
starts

with

“Adobe Flash Player”

AND
value
"DisplayName"
of

it

as
string ends
with

“Plugin”

AND
(value
"DisplayVersion"

of

it

as
string
as
version) >=
“12.0.0.70”

as
version)
of
keys
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

of
x32 registry
)

You can write relevance like the above for whatever software you are trying to install so that the fixlet will only be applicable if it needs to be installed and then it will also provide accurate success or failure.

For the situation you are talking about where you are going to take a second action only if the first succeeds, I would suggest doing this in 2 separate fixlets and deploy both. As long as the relevance is written correctly, the second will only run after the first succeeds. They can be deployed together in a baseline.

BUT, if you really want to chain multiple “actions” in the same action script, but only continue with the 2nd part if the first succeeds, then you can just do the following: (continuing with the adobe flash example)

// Install flash

continue if {

exists
keys
whose
(value
"DisplayName"

of

it

as
string
starts

with

“Adobe Flash Player”

AND
value
"DisplayName"
of

it

as
string ends
with

“Plugin”

AND
(value
"DisplayVersion"

of

it

as
string
as
version) >=
“12.0.0.70”

as
version)
of
keys
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

of
x32 registry
}

// do the next stuff

The only reason that you should ever need exit codes are in cases where you are running something that it is not easy to write relevance to detect success or failure. This is extremely rare, but it does happen.

(imported comment written by jgstew)

Also, you should be able to check what the exit code is that is being reported in the fixlet debugger and/or console:

wait msiexec /i
program.msi
/qn

dos echo {exit code of action}

Whenever I do this in the 8.2 fixlet debugger, the exit code seem to always be 52333753

The fixlet debugger is a quick way to get started, but always test using an action in the BigFix / IEM console when you hit an unexpected result. I come across issues like this all the time.

(imported comment written by MattPeterson)

We use exit code conditions quite a bit. I had issues with relevance substitutions well. This is what I do to get passed them (If you want to retrieve the exit code multiple times in a fixlet you will need a different parameter name each time). Creating parameters also lets you exit your action with that exit code.

//Run a command

wait run.cmd

//Set a parameter for the exit code

parameter “ExitCode” = "{if exist exit code of action then exit code of action as string else “52311”}

//If Exit code was not 0 then run another script

if {parameter “ExitCode” != “0”}

wait anotherscript.cmd

//Else continue

else

wait run2.cmd

//Now exit the script using the exit code from run.cmd

endif

exit {parameter “ExitCode”}

The problem I had was using exit code of action along with an if else statement. It worked fine as long as I didn’t have any prefetch commands in my aciton. If you are doing any downloads then the client will need to run all the if statements prior to starting the action. Since the commands haven’t run yet there is no exit code, so the client errors.

1 Like

(imported comment written by jgstew)

It is not clear to me from your last statement: Does your above code work fine if there are prefetchs, or not? Does this: {
if exist exit code of action then exit code of action as string else “52311”
} make that work?

(imported comment written by MattPeterson)

Sorry,

Yes the {
if exist exit code of action then exit code of action as string else “52311”
} makes it work even with prefetch statments.