popen()

含义:Open a PSL channel to a process

Format

popen(type,command,[instance],[username],[password])

Parameters

Parameter

Definition

type

command processor that interprets and executes command


Valid Values
the built-in command types OS or a valid user-defined

command type
Note: You cannot use PSL as the type parameter.

command

syntax of the submitted command

instance

optional application instance against which command executes


Default
application instance that is the nearest ancestor of command

username

optional user name under which the process channel is opened


Default
user name under which the popen() function is called

password

optional password under which the process channel is opened


Default
password under which the popen() function is called

Description

The popen() function spawns a process to execute a command of a defined type and returns a channel number which can then be used to read the command’s output or write messages to the command.

The popen() function can be used to submit a command to run in the background.Sometimes a long-running process like a daemon may be better run in the background, but care should be taken when submitting commands in the background.

Normally, when a command is executed by a parameter, or as a recovery action, it is executed in the foreground, and the parameter waits for the command script to finish before refreshing. This ensures that the recovery action is complete before the parameter is checked to see if an additional recovery action is required.However, if a recovery action is submitted in the background, the command script can finish before the recovery action is complete. When the command script finishes,the parameter refreshes. If the parameter is still in an alarm state, a second recovery action may start and conflict with the first recovery action.

Example

Code:

chan=popen("OS","ls /");
if (chan_exists(chan)) {output=read(chan);close(chan);
}
print(output,"\n");

Output:

BMC PSL function(33)-popen()_popen()