|Navigation: Language Reference > 13 - Built-in Functions >====== RUN (execute command) ======|
RUN( command [, waitflag ] )
|RUN||Executes a command as if it were entered on the DOS command line.|
|command||A string constant or variable containing the command to execute. This may include a full path and command line parameters.|
|waitflag||An integer constant, variable, or EQUATE indicating whether RUN should launch the command and wait for its termination, or immediately return after launching. If omitted or zero (0), control immediately returns to the statement following the RUN. If one (1), control returns to the statement following the RUN only after the command has completed its execution.|
The RUN statement executes a command to execute a DOS or Windows program. If the command parameter is a STRING variable, you must first use CLIP to remove trailing spaces (not necessary if the command is a CSTRING variable). Internally, RUN uses the appropriate API call to execute the command.
When the command executes, the new program is loaded as the ontop and active program. Execution control in the launching program returns immediately to the statement following RUN and the launching program continues executing as a background application if the waitflag is set to zero (0). The user can return to the launching program by either terminating the launched program, or switching back to it through the Windows Task List. Execution control in the launching program returns to the statement following RUN only after the command has terminated its execution if the waitflag is set to one (1).
If the command does not contain a path to the program, the following search sequence is followed:
|1.||The DOS current directory|
|2.||The Windows directory|
|3.||The Windows system directory|
|4.||Each directory in the DOS PATH|
|5.||Each directory mapped in a network|
The successful execution of the command may be verified with the RUNCODE procedure, which returns the DOS exit code of the command. If unsuccessful, RUN posts the error to the ERROR and ERRORCODE procedures.
The RUN statement now supports Vista UAC to open documents of registered types. If RUN is called for a document (not an EXE), additional parameters in passed string are ignored.
If a program name or path includes spaces or special characters it must be enclosed into double quote symbols for correct parsing.
Errors Posted: RUN may post any possible error
|RUN('notepad.exe readme.txt') !Run Notepad, automatically loading readme.txt file|
|RUN(ProgNameC) !Run the command in the ProgNameC CSTRING variable|
|RUN(CLIP(ProgNameS)) !Run the command in the ProgNameS STRING variable|
|RUN('command.com /c MyBat.bat',1) !Run the command and wait for it to complete|
|RUN('viewme.jpg',TRUE) !Run command open registered document type|
|RUN('“C:\Program Files\Text Pad 5\TextPad.exe”',TRUE) !Double quotes for long path|