How To: Pause Avenue code while system.execute() is running


Information provided are the instructions to pause an Avenue application while system.execute() runs another process.


1. Start a text editor, such as Notepad or WordPad.

2. Copy the following code into the text editor:

REM Example.bat
echo -------------------------------------------------
echo This portion of the program must:
echo 1. Run an application or commands of your choice.
echo 2. Create the flag file when finished No. 1.
echo -------------------------------------------------
REM Incser application or commands to run here:

The application or commands will run while the calling Avenue application is paused.

3. Save the file as c:\temp\example.bat and exit the text editor.

4. Open a new script window in ArcView.

A. Activate the Project window.
B. Click the Scripts icon.
C. Click New.

5. Copy this code into the new window:

'-- Test_Flag
'-- Wait for an external process launched with
'-- System.Execute() to complete before continuing.
'-- Calls: Example.bat

'-- Check for the existence of the flag file.
'-- When found, remove the script that av.DelayedRun() is using.
_count = 0
theFlagFile = "c:\temp\finished.txt".AsFileName
msgbox.info("Starting the test-for-flag-file" ++ _count.asstring,"")
if (File.Exists(theFlagFile)) then
msgbox.info("Flag file found. Moving on...","")
' av.run("MyScript_Part2","")
_count = _count + 1
msgbox.info("File not found. Starting loop again" ++ _count.asstring,"")

6. Name the script Test_Flag.

A. Select Properties from the Script menu.
B. Type in a new name in the Name field.
C. Click OK.

7. Select Compile from the Script menu.

8. Open a second script window.

9. Copy this code into the second script window:

'-- MyScript_Part1
'-- This section should go at the top of your script.
'-- Check for the existence of the flag file and delete if needed.
theFlagFile = "c:\temp\finished.txt".AsFileName
msgbox.Info(File.Exists(theFlagFile).AsString,"Is the Flag File There?")
if (File.Exists(theFlagFile)) then

'-- Start your code here
For each i in 0..5
myAnswer = MsgBox.YesNo( "Continue?", "ArcView", TRUE )
If (myanswer = false) then
'-- Create the flag file and run process

'-- Issue the Delayed.Run() request to loop and wait for the
'-- flag file to appear. If it appears, then finish,
'-- else, run av.delayed again from within the called script.

10. Name this script MyScript_Part1.

The Avenue application must be divided into two scripts. There is no method to pause a single avenue script and continue later in the middle of the script.

11. Select Compile from the Script menu.

12. Open a third script window.

13. Copy this code into the new window.

'-- MyScript_Part2
MsgBox.info("Process Finished","")
'-- Continue code here.

14. Name this script MyScript_Part2.

15. Open MyScript_Part1 and select Run from the Script menu.

MyScript_Part1 deletes a flag file that may have been left by a previous run. Then, the application code runs. When you reach the point where you need to pause the application, that is when you answer No to the Continue prompt, the Flag_Test script is executed and the Example.bat file is run. The Flag_Test loops every 5 seconds testing for the flag file. Once it detects the flag file, the script executes the remainder of the application by running MyScript_Part2.