A script can run any executable (ie, a program written in another language), including Windows programs.

To run an executable, you use the ITERATEEXE() function.

The first arg is the name of the desired program to run. This can contain the full path (ie, drive and directory names). You should also specify an extension if the program has one (ie, .exe or .cmd or .bat, etc). ITERATEEXE will run the program, and not return until that program has ended. If there is an error running the program, then ITERATEEXE will return an error message; otherwise, an empty string.

For example, here we run the program named Blort.exe:

/* Invoke the program 'blort.exe' in the C directory */
err = ITERATEEXE('C:\blort.exe')
IF err \== "" THEN SAY 'ERROR:' err
The second arg may be the name of any document or datafile you wish the program to operate upon. For example, here we tell Blort.exe to operate on a file named "MyFile.txt" in the directory "C:\MyDir":
err = ITERATEEXE('C:\blort.exe', 'C:\MyDir\MyFile.txt')

If you wish to have ITERATEEXE run the program numerous times upon several files whose names match a specific pattern, then you can use wildcards in the name. For example, here we tell ITERATEEXE to run Blort.exe to operate on all files in "C:\MyDir" that end with the extension ".txt":

err = ITERATEEXE('C:\blort.exe', 'C:\MyDir\*.txt')
Note: The program will not simultaneously operate upon all data files at once (unless you use the "M" option discussed below). Rather, ITERATEEXE will run the program, passing the name of the first matching file. When the program ends, ITERATEEXE will run the program again on the next matching file. This process continues until all matching files are processed by the program. ITERATEEXE will not return until that process is complete.

To have the program operate upon all files in a directory, simply specify the directory, ending in a slash. Here we operate upon all files in "C:\MyDir":

err = ITERATEEXE('C:\blort.exe', 'C:\MyDir\')

Sometimes, a program may accept both a source file name, as well as a destination name. For example, assume that you have a program named Convert.exe which takes a text file and turns it into an HTML file. When you run the program, you can specify the text filename, as well as the filename you wish for the resulting HTML file. In this case, ITERATEEXE allows passing a third arg, which is the desired destination name. For example, here we call Convert.exe to turn MyTextFile.txt into MyHtmlFile.htm:

err = ITERATEEXE('Convert.exe', 'MyTextFile.txt', 'MyHtmlFile.htm')
You can also use wildcard patterns on the destination name, and specify a complete path. For example, here we call Convert.exe to turn all files that end in .txt to html, with destination names that are the same except for replacing the .TXT extension with .HTM, and place the destination files in "C:\Html":
err = ITERATEEXE('Convert.exe', '*.txt', 'C:\Html\*.htm')

A program may allow you to specify other args, such as "flags" or "options" that determine how the program runs. For example, let's assume that Convert.exe allows you to specify -q to suppress error messages. This must be specified before the filenames. In this case, you can pass this extra string as the fourth arg to ITERATEEXE:

err = ITERATEEXE('Convert.exe', '*.txt', '*.htm', '-q')
If the program expects the extra args after the filenames, then pass the extra string as the fifth arg to ITERATEEXE:
err = ITERATEEXE('Convert.exe', '*.txt', '*.htm',, '-q')
Note: You can specify both "before" and "after" strings.


Running by file association

Alternately, the first arg to ITERATEEXE can be the name of some document or data file that is associated with some program. For example, specifying MyPage.htm will cause the program associated with .htm files to open that file:

/* Invoke whatever program is associated with .HTM extension,
 * and have it operate upon the specific file MyPage.htm.
 */
err = ITERATEEXE('MyPage.htm')


Running by shell action

Some files support "actions". The actions a file can support depend upon its file extension. For example, a file whose name that ends in .WAV may support a "Play" action to play the audio file using Media Player. A file whose name ends in .TXT may support a "Print" action to print out the text file.

Note: To see what actions a file supports, move the mouse pointer over that file's icon, and click the right mouse button once to display its pop up menu. The actions that file supports are listed first in the menu. For example, you'll typically see "Open" listed first, since most every file supports an open action. When you issue an open action on a file, if the file is an EXE, then that EXE is run. If the file is a data file, then whatever EXE is associated with that data file is run, and the EXE typically loads that data file automatically. For example, if you perform an open action on a text file, it will typically open up in Notepad. If the file supports the print command, then you'll see the word "Print" in the menu too. Some files may support additional actions. For example, a folder icon has an "Explore" action which will cause an explorer window to open showing the contents of that folder.

To run by shell action, pass the desired "action string" as the first arg to ITERATEEXE. Pass the name of the file to operate upon as the second arg. Finally, you must pass "A" as the sixth arg to indicate that you're specifying an action. For example, here we play the file myvideo.mpg:

err = ITERATEEXE('Play', 'myvideo.mpg', , , , 'A') 
You can also use wildcards, and paths. Here we print all files in the directory C:\MyDir whose names end in .TXT:
err = ITERATEEXE('Print', 'C:\MyDir\*.txt', , , , 'A') 
Note: If you omit the first arg, then ITERATEEXE() defaults to sending the data file(s) to the printer. So, this is the same as specifying "Print" for the action.


Asyncronous operation

Normally, ITERATEEXE doesn't return until the launched program ends. By specifying an option of 'M' as the sixth arg, then ITERATEEXE will return immediately after launching the program. (ie, The program will run simultaneously while your script continues). For example, here we launch Blort.exe without waiting for it to end:

err = ITERATEEXE('Blort.exe', , , , , 'M')
Here we issue an "Unzip" action on the file "myarchive.zip" and return immediately while the action is carried out.
err = ITERATEEXE('Unzip', 'myarchive.zip', , , , 'AM')