CA Harvest Software Change ManagerCA Harvest Software Change Manager - OpenMake Meister
Issue/Introduction
The return codes of the invoked remote program executed by hexecp are not being passed as expected.
This occurs when the return code of the remote program is > 0 The remote program is invoked and returned an exit code > 0, but the hexecp returns in any case an exit code of 3.
Expected: According to the documentation, if the remote program is found and invoked, the return code of the program should be then passed to the return code of hexcep.
%ERRORLEVEL% is always the exit code of the last executed program.
When hexecp invokes a batch file directly, the return code of the batch file would get set to %ERRORLEVEL%
hexecp returns 3 for all anticipated failures of the invoked program. So for all non zero return codes from the -prg option will get converted as 3 and returned.
If hexecp is ran through batch file or any script file, the executed program will be hexecp. So the return code of hexecp is getting set to %ERRORLEVEL%
Finally the conclusion is - When we run hexecp from other scripts, %ERRORLEVEL% would be the return code of hexecp. It does not return the code of the program mentioned in -prg option. - We can suggest a similar workaround as described in the "Additional Information"
Additional Information
This is an example to reproduce, and a workaround proposed for the same:
Set up a test with the following batch script named testExitCode.bat
REM ---------- @echo off echo Exiting with error code %1 exit /b %1 REM ----------
Then, ran that from hexecp with various exit codes and hexecp’s return message always reports the correct return code:
Execution of program: C:\Users\Administrator\testExitCode.bat 0 was successful.
Then put hexecp in a wrapper script named tryit.bat:
REM ---------- @echo off hexecp -m %computername% -rport 9000 -usr Administrator -pw <pwd> -syn -prg "C:\Users\Administrator\testExitCode.bat %1" echo hexecp is done, exit code was %ERRORLEVEL% REM ----------
No matter what the exit code was returned from the batch script, if it’s not 0, the error code returned from hexecp is 3
C:\Users\Administrator>tryit 5
Attempting to log into remote agent...
Connected to remote agent.
Exiting with error code 5
ERROR: Execution of program C:\Users\Administrator\testExitCode.bat 5 has failed. Exit code : 5.
hexecp is done, exit code was 3
C:\Users\Administrator>tryit 15
Attempting to log into remote agent...
Connected to remote agent.
Exiting with error code 15
ERROR: Execution of program C:\Users\Administrator\testExitCode.bat 15 has failed. Exit code : 15.
hexecp is done, exit code was 3
C:\Users\Administrator>tryit 0
Attempting to log into remote agent...
Connected to remote agent.
Exiting with error code 0
Execution of program: C:\Users\Administrator\testExitCode.bat 0 was successful.
hexecp has been executed successfully.
hexecp is done, exit code was 0
Hexecp reports the script’s return code in the message it returns but doesn’t carry it forward to be the exit code from hexecp. The workaround would be to capture the exit code from hexecp’s return message in the wrapper script.
Example:
REM ---------- @echo off setlocal enabledelayedexpansion set _cmd=hexecp -m %computername% -rport 9000 -usr Administrator -pw <pwd> -syn -prg "C:\Users\Administrator\testExitCode.bat %1" for /f "usebackq skip=3 tokens=4 delims=:" %%a in (`%_cmd%`) do set _errcode=%%a echo hexecp is done, exit code was %_errcode% REM ----------
When being run, we can know what the actual return code was