RunProgram


 

RunProgram>path

 

Executes a specified file.  Files than can be executed are .exe, .bat, and .com files.

 

By setting the RP_WAIT variable to 1 prior to issuing the Run Program command the script will wait until the program launched by Run Program has terminated before continuing.  The default value of RP_WAIT is 0.

 

Set RP_WAIT to 2 if you want the script to wait until it thinks the program is idle and ready for input.  This only works for GUI applications and may not be appropriate for all applications.  Some applications may appear ready for input before they really are.  See WaitWindowOpen and WaitReady for other ways to wait until an application is ready.

 

By setting the RP_WINDOWMODE variable programs can be executed minimized, maximised, hidden or normal.  RP_WINDOWMODE can be one of the following :

 

0: Hidden

1: Normal (default)

2: Minimized

3: Maximized

 

If you set RP_WINDOWMODE it is used by all subsequent Run Program commands, so remember to set it back if you don't want the same window mode to be used each time.

 

By default a message is displayed if this command encounters an error when running the specified program.  Error messages from this command can be suppressed by setting RP_DISPLAYERROR to 0.

 

The result of the Run Program command is stored in the variable RP_RESULT.

 

The value of RP_RESULT differs depending on whether RP_WAIT is set to 0 or 1.

 

If RP_WAIT is 1 RP_RESULT will be set to the process exit code of the called program if successful.  Therefore it will be zero if successful and the program does not return an exit code.  -1 indicates that an error occured.  If an error occurs the return code will be -1 followed by a colon followed by the error code.  E.g. -1:2

 

If RP_WAIT is 0 (default) a value greater than 31 indicates success and the following values represent errors :

 

0 - The system was out of memory, or the executable file was corrupt, or relocations were invalid. (RP_WAIT=0 only)

2 - The file was not found.

3 - The path was not found.

5 - An attempt was made to dynamically link to a task, or there was a sharing or network protection error.

6 - The library required separate data segments for each task.

10 - The Windows version was incorrect.

11 - The executable file was invalid. It was either not a Windows-based application or there was an error in the .EXE  image.

12 - The application was designed for OS/2.

13 - The application was designed for MS-DOS 4.0.

14 - The type of executable file was unknown.

15 - An attempt was made to load a real-mode application (developed for an earlier version of Windows).

16 - An attempt was made to load a second instance of an executable file containing multiple data segments that were not marked "read-only."

17 - Attempt in large-frame EMS mode to load a second instance of an application that links to certain non-shareable DLLs already in use.

18 - Attempt in real mode to load an application marked for protected mode only.

 

To run as admin, set RP_ADMIN to 1.

 

Capturing STDOUT: To run a program, wait for it to complete and then view the output to STDOUT set RP_CAPTURESTDOUT to 1 first and then look at the value of RP_STDOUT afterwards. Note this will only work for apps and commands that do output something to STDOUT and it will also ALWAYS wait until the process has terminated, therefore RP_WAIT has no effect when usng RP_CAPTURESTDOUT. Note also that when using RP_CAPTURESTDOUT, RP_ADMIN=1 will have no effect.

 

If attempting to run a 64 bit system process residing in the System32 folder on Windows x64 you can set RP_WIN64PROCESS to 1 to temporarily disable file system redirection.  Alternatively refer to SYS_NATIVE instead of SYS_DIR.

 

Abbreviation : Run

See also: ExecuteFile

 

Example

 

To open Notepad:

 

RunProgram>notepad.exe

 

A path may be specified if necessary:

 

RunProgram>c:\my programs\eudora\eudora.exe

 

To start notepad minimized:

 

Let>RP_WINDOWMODE=2

RunProgram>notepad.exe

 

Capturing STDOUT:

 

Let>RP_CAPTURESTDOUT=1

RunProgram>cmd.exe /c dir %USERDOCUMENTS_DIR% && echo hello world

MessageModal>RP_STDOUT