Control Process Runner from External Process with Return Code
This topic describes the behavior of Process Runner depending on the return code of an external process. External process can return 0
to indicate that there was no error and Process Runner should continue further. Or it can return 1
and indicate that there was an error and Process Runner should not continue further.
This behavior is valid only if you have configured Process Runner to wait for the external process. The following table explains the different scenarios.
Script Return |
Wait Option |
Stop On Error Settings |
Process Runner behavior |
---|---|---|---|
0 |
No Wait |
N/A |
Always continues further |
1 |
No Wait |
N/A |
Always continues further |
0 |
Wait until terminated |
Unchecked |
Waits till all messages are responded and then executes ahead |
1 |
Wait until terminated |
Unchecked |
Waits till all messages are responded and then executes ahead |
0 |
Wait until seconds (2) |
Unchecked |
Waits for 2 seconds to respond and then executes ahead |
1 |
Wait until seconds (2) |
Unchecked |
Waits for 2 seconds to respond and then executes ahead |
0 |
Wait until terminated |
Checked |
Waits till all messages are responded and then executes ahead since there is no error retuned by script |
1 |
Wait until terminated |
Checked |
Waits till all messages are responded and then returns without executing ahead |
0 |
Wait until seconds (2) |
Unchecked |
Waits for 2 seconds to respond. If user responds during that time , error code is trapped and in this case there is no error so executes ahead. If used doesnt respond during that time, it just moves ahead without trapping error code. |
1 |
Wait until seconds (2) |
Unchecked |
Waits for 2 seconds to respond. If user responds during that time, error code is trapped and in this case there is error so execution stops. If used does not respond during that time, it just moves ahead without trapping error code. |
The following is an example of a VBScript file with return error and its behavior with process settings.
dim a '---- var declaration
a = Inputbox("Enter number") '----Accept value of a from keyboard
if a >= 10 then '----Check value of a
msgbox 100 '----Show 100
wscript.quit(0) '---- Error code 0 is returned (No error state)
else
if a >= 0 then '----Check value of a
msgbox a '----Show 10
wscript.quit(0) '---- Error code 0 is returned (No error state)
else
msgbox -1 '----Show -1
wscript.quit(1) '---- Error code 1 is returned (Error state)
end if '----Close if
end if '----Close if
This script takes command-line parameters and shows them one by one and terminates with error code 0
(no error). If no parameter is provided, it displays a message and terminates with the error code 1
.
The following is an example of a JavaScript file that repeats any statement within the while loop 100 times. It increments the loop variable after each iteration.
a = 1; //----initialization of a
while ( a <= 100 ) //----check value of a, if it is <= 100
{
//----comment statement
//----write any code that you want to repeat here
i++; //----increment the loop control variable a
} //----close loop
For catching the error generated from external application, Process Runner uses the environment variables called PRERRORLEVEL
and PRERRORMSG
. When the external process wants to return a value as exit status to Process Runner, you can use the environment variables and set its value to the desired exit code. The Pre-run or Post-run feature can catch this value and control further processing accordingly. Process Runner considers non-zero value of that variable as an error state and zero as a success. To get an error message back to Process Runner, you can use the PRERRORMSG
environment variable.