SPAWN Procedure (UNIX)

Spawns a child process to execute a given command.

Usage

SPAWN [, command [, result]]

Input Parameters

command—(optional) The name of the command to spawn.

If present, must be of type string. Under UNIX, command can be an array each element is passed to the child process as a separate parameter.

If not present, starts an interactive shell and PV‑WAVE execution suspends until the new shell process terminates.

Note:

Shells that handle process suspension (e.g., /bin/csh) offer a more efficient way to get the same effect.

Output Parameters

result—(optional) Indicates where the result is to be directed.

If present, places the output from the child process into a string array (one line of output per array element).

If not present, sends the output from the child shell process to the standard output stream.

Keywords

Count—Number of string elements returned if output is a string variable.

F77_Unformatted—If set, opens a pipe to the spawned process in a mode to do unformatted FORTRAN F77 input/output.

Noshell—If present and nonzero, specifies that command should execute directly as a child process without an intervening shell process. In this case, command must be specified as a string array in which the first element is the name of the command to execute and the following parameters are the parameters to be passed to the command.

Noshell is useful when performing many spawned operations from a program and speed is a primary concern. Since no shell is present, wildcard characters are not expanded, and other tasks normally performed by the shell do not occur.

Nowait—If set, causes the calling process to continue executing in parallel with the subprocess. Otherwise, the calling process waits until the subprocess completes.

Pid—A named variable for storing the process identification number of the child process.

Sh—If present and nonzero, forces the use of the Bourne shell.

Unit—A named variable for storing the number of the file unit.

If present, causes SPAWN to create a child process in the usual manner, but instead of waiting for the specified command to finish, SPAWN attaches a bidirectional pipe between the child process and PV‑WAVE. From the PV‑WAVE session, the pipe appears as a logical file unit. The other end of the pipe is attached to the child process standard input and output.

Note:

If the Unit keyword is used, the command parameter must also be present, and result is not allowed.

Discussion

Under UNIX, the shell used (if any) is obtained from the SHELL environment variable.

Once the child process is started, the PV‑WAVE session can communicate with it using the normal input/output facilities. After the child process has done its task, the CLOSE procedure is used to delete the process and close the pipe.

Since SPAWN uses GET_LUN to allocate the file unit, FREE_LUN should be used to free the unit.

Example

SPAWN,'ps -a'

See Also

CALL_UNIX, CLOSE, FREE_LUN, GET_LUN, LINKNLOAD, UNIX_LISTEN, UNIX_REPLY

Also see the PV‑WAVE Application Developer’s Guide.