SD Job : return exit code of a called script
search cancel

SD Job : return exit code of a called script

book

Article ID: 10086

calendar_today

Updated On:

Products

CA Client Automation - IT Client Manager CA Client Automation

Issue/Introduction

SD Job returns the exit code of the script defined in the SD procedure. If the script called a second script, it will not report the exit code of the second script. How to report this ?

Example :

Package TEST_VBS 1.0 contains 2 files : install.bat and test.vbs

 

The install procedure executes install.bat

install.bat contains these lines :

cscript.exe test.vbs

echo test.vbs executed

 

test.vbs contains these lines :

Wscript.Echo "Hello"

WScript.Quit 123

 

When the package is sent to a machine, the SD Job is always is status OK because exit code is exit code of last line of install.bat script (which is echo command).

 

How to return the exit code (123) of vbs script in this example ?

Environment

Client Automation - All Versions

Resolution

Add these 3 lines just after call of the second script :

 

SET RC=%ERRORLEVEL%

echo [RESULT] > "%SDROOT%\ASM\CONF\ASMINSTW.RES"

echo ErrorCode=%RC% >> "%SDROOT%\ASM\CONF\ASMINSTW.RES"

 

File %SDROOT%\ASM\CONF\ASMINSTW.RES is used by SD Agent to report the exit code of the job.

 

Example :

After adding the 3 lines in install.bat :

 

SD Job reports the exit code of test.vbs script

 

This solution could be applied for vbs script but for other kind of script too like .cmd, .bat, .ps etc...