The SPAWN procedure spawns a child process to execute a command or series of commands. Under Unix, the shell used (if any) is obtained from the SHELL environment variable. Under VMS, the DCL command language interpreter is used. Under Windows 3.1 and Windows 95, a DOS window is opened. Under Windows NT, a Command Shell is opened. On the Macintosh, SPAWN opens specified files or applications.
A string containing the command(s) to be executed.
If
Command
is not present, SPAWN starts an interactive command interpreter process. Under Unix, the default shell is used. IDL execution suspends until the new shell process terminates. Under Unix, shells that handle process suspension (e.g.,
/bin/csh
) offer a more efficient way to get the same effect.
If Command is not present under Windows, SPAWN creates an interactive MS-DOS window or NT command shell window as a child process. Quit the shell session by entering "EXIT" at the prompt.Under Windows 3.1 and Windows 95 (but not under Windows NT), the SPAWN command calls a PIF file named idlspawn.pif. This file is installed automatically in the IDL binary directory (usually C:\rsi\idl50). You can change any options you wish in idlspawn.pif file, with the exception of the Program Filename (COMMAND.COM) and the Window Title ("IDL Spawned Process").
Command must be of type string. Under VMS, it is restricted to being a scalar. Under Unix, it can be a string array (each element is passed to the child process as a separate argument) if used in conjunction with the NOSHELL keyword. If a new Unix shell process is started (that is, if the NOSHELL keyword is not specified), Command must be a scalar string.
On the Macintosh, Command must consist of the names of files to be opened. Multiple filenames can be entered. If the first filename is an application, it is used to open the remaining files. Otherwise, each file is opened by the application that owns it. IDL execution resumes when the files have been opened.
Set this keyword to specify that Command should execute directly as a child process without an intervening shell process. In this case, Command should be specified as a string array in which the first element is the name of the command to execute and the following arguments are the arguments to be passed to the command (C programmers will recognize this as these are the elements of the argv argument that Unix passes to the child process main function). Since no shell is present, wildcard characters are not expanded, and other tasks normally performed by the shell do not occur. NOSHELL is useful when performing many SPAWNed operations from a program and speed is a primary concern.
Some Unix systems drop characters when the tty mode is switched between normal and raw modes. IDL switches between these modes when reading command input and when using the GET_KBRD function. On such systems, IDL avoids losing characters by delaying the switch back to normal mode until it is truly needed. This method has the benefit of avoiding the large number of mode changes that would otherwise be necessary. Routines that cause output to be sent to the standard output (e.g., I/O operations, user interaction and SPAWN) ensure that the tty is in its normal mode before performing their operations.
If the NOTTYRESET keyword is set, SPAWN does not switch the tty back to normal mode before launching the child process assuming instead that the child will not send output to the tty. Use this keyword to avoid characters being dropped in a loop of the form:
WHILE (GET_KBRD(0) NE 'q') SPAWN, command
This keyword has no effect on systems that don't suffer from dropped characters.
Set this keyword to force the use of the
/bin/sh
shell. Usually, the shell used is determined by the SHELL environment variable.
If UNIT is present, SPAWN creates a child process in the usual manner, but instead of waiting for the specified command to finish, it attaches a bidirectional pipe between the child process and IDL. From the IDL 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. The UNIT keyword specifies a named variable into which the number of the file unit is stored.
Once the child process is started, the IDL session can communicate with it through the usual input/output facilities. After the child process has done its task, the CLOSE procedure can be used to kill 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.
If UNIT is present, Command must be present, and Result is not allowed.
If this keyword is set, the spawned subprocess does not inherit command language interpreter symbols from its parent process. You can specify this keyword to prevent commands redefined by symbol assignments from affecting the spawned commands, or to speed process startup.
If this keyword is set, the spawned subprocess does not inherit process logical names from its parent process. You can specify this keyword to prevent commands redefined by logical name assignments from affecting the spawned commands, or to speed process startup.