SD Job : return exit code of a called script

Document ID : KB000010086
Last Modified Date : 14/02/2018
Show Technical Document Details
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

Untitled.jpg

 

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).

Untitled2.png

 

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

Instructions:

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 :

Untitled3.jpg

SD Job reports the exit code of test.vbs script

Untitled4.jpg

 

 

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