# Directives

INVOKE | Execute Operating System Command

## Format

To invoke command:

INVOKE [CONTROL] [HIDE] [WAIT] command$[,ERR=stmtref]

Where:

command$ | String expression to be passed to the operating system command processor for execution.
task$ | Windows task. String expression.
stmtref | Program line number or statement label to which to transfer control.
CONTROL | (Windows Only) Keyword that, if supplied, will request that the command "Run as administrator".
HIDE | (Windows Only) Keyword that, if supplied, will request that the command be run in hidden/minimized window.
WAIT | (Windows Only) Keyword that, if supplied, will request that system wait for the command to complete before returning.

#### Note:
In Command mode, PxPlus interprets a statement as an INVOKE directive if it begins with a double quotation mark ( " ).

## Description

The INVOKE directive enables a statement in a program to be processed by the operating system as if it were entered as a command from the terminal. It provides access to most operating system utilities and facilities from within a PxPlus program.

In Execution mode, character strings are passed from a program to the operating system.

In Command mode, entering a line of code that starts with a quotation mark (i.e. "statement"[, ERR=stmtref]) is the same as using the word INVOKE to start the directive.

In Windows, to accommodate the way Windows searches for programs and determines the type of program to run, it is best to identify the type of file in the Command line (e.g. "XCOPY.EXE" or "MYJOB.BAT").

#### Note:
Under WindX, you can use INVOKE "[WDX]..." or INVOKE "[LCL]..." to encapsulate a directive or statement that is not supported across a WindX connection. See [WDX] Direct Action to Client Machine and [LCL] Access to Users Local Machine.

If you are not concerned about the return status of a command and are running PVX UNIX and PVX Windows, there is no difference between using an INVOKE directive and the SYS( ) function. When SYS( ) is used under Windows, PxPlus waits for the spawned task to complete or for the program to be reactivated via the mouse. When the INVOKE directive is used under Windows, PxPlus spawns the task and continues without waiting for the task to complete.

Use the INVOKE WAIT directive to wait for the task, which is the same as using the SYS( ) function. If the 'IW' system parameter is disabled (Off), the user can force PxPlus to exit the wait state and continue to run by clicking on the PxPlus window or changing focus to it.

Use INVOKE HIDE to spawn a task in a minimized window.

#### Note:
Use the SYS( ) function instead of the INVOKE directive if you wish to test the successful conclusion of an operating system command.

Invoke

INVOKE command$[,ERR=stmtref]

Use the INVOKE directive to have the operating system treat a character string from a program as an operating system command from the terminal.

Example:

> invoke env("COMSPEC")+" /K DIR C:\WINDOWS"

#### Note:
The env("COMSPEC") when running on Windows determines the correct command processor to be used. Some Windows commands (such as COPY and DIR) are built into command process and can be called using this type of statement.

Background Tasks in PxPlus

Use INVOKE to start a background process in PxPlus. Under UNIX, output generated by the operating system command may result in strange display behavior. In particular, PxPlus will not know where the cursor is nor be able to restore the screen if a window is pushed/popped. This is because the output from the operating system command is not intercepted by PxPlus and is therefore unknown to it.

When you INVOKE another copy of PxPlus under UNIX, it is recommended that you also redirect stdin, stdout, and stderr to null files.

Example:

> invoke arg(0)+"program >/dev/null >2/dev/null </dev/null"

#### Note:
ARG(0) returns the name of the 'pxplus' executive as entered in the original Command line. Make sure that this is an absolute pathname or that PxPlus can be found in the system path search rules.

## See Also

SYS( ) Invoke Operating System Command
'IW' Force INVOKE WAIT