cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
IAUser123
Level 3

Executing scripts

Hi,

I am working with InstallAnywhere 2008 Standard edition. I am using 'Execute Script/Batch file' option to execute few scripts to install various softwares. I would like to execute all these installation scripts based on the output of a script. I mean to say that if this script returns 'o' then execute all other scripts else if it returns '-1' then all other scripts should not be executed. Can anyone tell me how to acheive this?

Please get back to me for any further details.

Thanks in advance,

Regards,
IAUser123
Labels (1)
0 Kudos
(6) Replies
RobertDickau
Flexera Alumni

The first Execute Script/Batch File action should set the value of an IA variable to the script return value ($EXECUTE_EXITCODE$, by default); you could then use that variable in a rule on subsequent script actions (or on an action group containing the other script actions).
0 Kudos
IAUser123
Level 3

Hi,

Thanks for the reply. Could you please explain briefly on how to use the variable ($EXECUTE_EXITCODE$)?


Regards,
IAUser123
0 Kudos
RobertDickau
Flexera Alumni

To use the value of a variable in a conditional statement, you can select the Rules tab in an action's customizer, click Add Rule, and select Compare InstallAnywhere Variables. In the rule's settings, then, you can compare $EXECUTE_EXITCODE$ with the desired return value.
0 Kudos
scarney
Level 5

I have been lurking in the IA forum and some other script/batch programming forums to figure out why I am not getting this to work.

[LIST=1]
  • Vitals
    [LIST=a]
  • InstallAnywhere 2012 Enterprise Edtion with SP1 patch
  • Windows XP with SP3 patch applied

  • Desired workflow
    [LIST=a]
  • In the Pre-Install actions, I did an Add Action -> Execute Script/Batch file:
  • I cut an paste my batch script into the panel after debugging it and making sure it works.
  • We are performing an upgrade in the field which means we are installing newer files over older ones.
  • The batch script's function is to ensure that a certain list of files has the read-only attribute set. If the attribute is not set for any of the files in question, that means we have a broken system and we don't want to do the upgrade.
  • My intent is for the script to exit with a non-zero return code and have that be captured in the $EXECUTE_EXITCODE$
  • Then I added a rule at the Install action to Compare InstallAnywhere Variables Numerically. I am comparing $EXECUTE_EXITCODE$(left parameter) to 0. In the bottom it says Perform only if: I presume that means perform the install only if $EXECUTE_EXITCODE$ is 0.

  • Trouble
    [LIST=a]
  • For testing, I deliberately setup a system where the read-only attribute was unset for all of the artifacts we care about.
  • I ran the script outside of InstallAnywhere and it is properly logging the problem and exiting with a return code of 1.
  • When I run it inside of InstallAnywhere, it does the logging stuff correctly and bails out where it should but the return code is not being captured in $EXECUTE_EXITCODE$.
  • Now I found an entry from 2008 in which that user cautioned not to do exit /b 1 but do exit 1. He said the '/b' hoses things up. So, I removed the '/b' part from my script. No luck.
  • Then I saw another post on a Batch scripting forum in which someone recommeded @%COMPSPEC% /C exit 1. That didn't work either.



    Question, how do I get the return code from the script captured into $EXECUTE_EXITCODE$. I am probably the gazillionth person to ask. Sorry ... New to batchscripting. Old Unix hand. And while I am at it, can I cut an paste a powershell script in this action, instead?
  • 0 Kudos
    scarney
    Level 5

    I knew I would find the answer after bugging you folks. See http://stackoverflow.com/questions/4632891/exiting-batch-with-exit-b-x-where-x-1-acts-as-if-command-completed-successfu.

    The script has to look like this:

    cd $USER_INSTALL_DIR$

    :: Get the list of files with the read-only attribute set.
    :: This post-install script restores the read-only attribute
    :: to the files in the list.
    ::
    :: If the system encounters a system where there is not
    :: read-only attribute set, bail out with an error.
    dir /a:r-h /s /b>%AttrFile%
    if %errorlevel% neq 0 (
    call :complain "ERROR: %errorlevel% : read-only attribute not set for any file"
    goto :end
    )

    ....
    :: Name : complain
    ::
    :: Purpose : Issues error message to logfile.
    ::
    :: Parameters :
    :: msg - Error message handling
    :: %1 - Error Message
    ::
    :: Increments wmerrors
    ::
    :complain
    setlocal
    (set msg=%~1)
    set emsg="[%date% %time% %wmhost%] %msg%"
    echo %emsg:~1,-1% >> %LogFile%
    endlocal
    goto :eof
    ...

    :end
    %comspec% /c exit %errorlevel%


    That works. The entry I saw at the link is:


    I was confused for a bit, so this is just a note for others that you literally need that to be the last line of the file. It won't actually exit the batch, just set the error code. Calling EXIT /B %ERRORLEVEL% directly after it doesn't always seem to work either. The only reliable method I found was to use IF ERRORLEVEL 1 goto :end and have a label :end just before the last line with %COMSPEC% /C EXIT %ERRORLEVEL%>NUL – Jordan Evens Jan 10 '11 at 14:34
    buzz3791
    Level 3

    @scarney Thank you for this workaround.  Still required with InstallAnywhere 2017 ðŸ˜¥

    0 Kudos