If you have a third party application which creates data files that have to be processed by your system there are two ways in which this can be done:
This document describes how to create an application which runs in the background, wakes up every so often looking for files to process, then goes back to sleep again. It will keep doing this until told to stop.
This utility makes use of the
$timeout function which fires the <ASYNC INTERRUPT> trigger after a specified period of inactivity. As the timeout interval can only be expressed in whole minutes if something smaller is required you will have to use another method. If you would like details of an alternative method I have created which allows intervals as small as 1 second then please refer to my follow-up article Unattended File Polling with short Intervals.
The sample code which provides a working example of what is described in this document contains the following components:
macro "^ACCEPT". This fires the <ACCEPT> trigger of the current form (which should be POLL_002) when each timeout interval expires.
Note that when a timeout event is fired the clock does not start ticking for the next interval until all processing has been completed and keyboard input is requested. This means that POLL_002 cannot be re-activated while the previous activation is still processing. The periods between each unattended activation will be equal to the timeout interval.
For those of you who are too lazy to download my sample code here is the portion which obtains the directory listing. Note that for Windows NT it is possible to use the
activate command, while for Windows 95 you have to use the
spawn command instead. This is due to bug #19136 which has been outstanding for several years.
params string pi_InputString : IN endparams variables string lv_OprSys string lv_FileList endvariables getlistitems/id/local pi_InputString ; load into local variables lv_OprSys = $oprsys ; get id of operating system ; look for any files existing in the IN directory ========================= if (lv_OprSys = "L") ; operating system = NT $1 = "cmd.exe /c DIR /b /on %%$inpath$%%$file_mask$" activate "OS".commandout($1,lv_FileList) if ($procerror) call PROC_ERROR($procerrorcontext) return(-1) endif else ; operating system not = NT $1 = "set dircmd=/ogn%%^" ; do not pause for large list $1 = "%%$1dir /b /on %%$inpath$%%$file_mask$ > %%$inpath$filelist.txt" $1 = "%%$1%%^cls" ; append 'cls' to close window $2 = "%%$inpath$doscmnd.bat" file_dump $1,"%%$2" ; create batch file to obtain list if ($status < 0) return(-1) spawn "#%%$2" ; execute this file if ($status < 0) return(-1) file_load "%%$inpath$filelist.txt",lv_FileList ; load list endif if (lv_FileList != "") call SCAN_FILE_LIST(lv_FileList) ; process the list endif if ($delete_list$ != "") ; if list not empty call DELETE_FILES($delete_list$) ; delete input file(s) endif
13th December 2000
|21st Nov 2001||Added reference to follow-up article Unattended File Polling with short Intervals|
Back to TOP.