#ExecTimeout – System Variable






#ExecTimeout Documentation


Description

The #ExecTimeout system variable specifies the maximum number of seconds that WinTask will wait before killing the current script execution.

Usage

If you need to run a script at regular intervals whatever error is reported, use #ExecTimeout in conjunction with #ScriptAfterTimeout$ in order to rerun within a clean desktop whatever happened during the previous execution.

Syntax

#ExecTimeout=n

Remarks

When n seconds have elapsed, if script execution is not finished, the script is killed, and the execution is stopped. If the system variable #ScriptAfterTimeout$ is filled with a value, the script named in this variable is then launched.

The use of this system variable along with #ScriptAfterTimeout$ allows recreating a “clean” environment if the script fails for any reason and so you can rerun the same script exactly in the same state as if it was the first time; see below the example code.

If no script after timeout is specified and script execution is killed due to #ExecTimeout value, TaskExec returns a -9 code (value for the return code of the Run function).

#ExecTimeout set to 0 means that there is no timeout.

If #ExecTimeout is set to a value lower than the execution time so far, #ExecTimeout is forced to 0.

See also

#ScriptAfterTimeout$

Examples

#ExecTimeout = 20
/*This script launches Notepad and the demo page www.wintask.com/demos. After #ExecTimeout seconds (here at 10), the script is killed and the script killprocesses is launched. This last script kills the two processes Notepad and Iexplore, so the environment before launching the first script is restored.
*/
'Maximum execution time set at 10
#ExecTimeout=10
'If the timeout is reached, run the killprocesses script
#ScriptAfterTimeout$="killprocesses"
 
'Some actions, launch notepad, launch a website
Shell("notepad")
 
StartBrowser("IE", "www.wintask.com/demos")
UsePage("WinTask Demonstration Pages")
'A long pause and so the script takes more than 10 secs to execute  
pause 20

' Script killprocesses-------------------------------------------------
'This other script kills the applications opened by the main one
KillApp("notepad.exe",1)
killApp("iexplore.exe",1)
'This other example shows how to take a screenshot of the desktop after #ExecTimeout.
'If the script does not finish after 30 secs (#ExecTimeout), the execution is stopped
'and the script called AfterTimeout is executed (the file AfterTimeout.rob must exist).
#ScriptAftertimeout$="AfterTimeout"
#Exectimeout=30
 
#Actiontimeout=15
 
Shell("notepad")
'The window does not exist and so the script fails.
UseWindow("toto")
' Script AfterTimeout-------------------------------------------------
'The script called after the main script is killed has just one line:
ret=Hardcopy("C:\program files (x86)\wintask\scripts\error.jpg",1,1)