std_input The (optional) standard input to be sent to the command.
std_output The standard output produced by the command (see trap_ouput).
trap_output Flag controlling whether the command's standard output is trapped or not.
async Flag controlling whether command shell is run asynchronously. If set, a "do!" message will return immediately after spawning the child process. Async cannot be on if trap_output is on.
std_input[=?] Set/get the standard input for the command.
std_output? Get the standard output produced by executing the command.
do! Execute the command. As a convenience, this message also returns the standard output of the command allowing easy chaining of commands (see example below). Further do! messages to this instance are blocked until the asynchronous process terminates and the pid is reset to 0 by "wait!" or
"check_status!".
pid? Returns the background process id of the shell.
status? Returns the status of the background process. 0=terminated, 1=running (set by a do! message), 2=stopped (set by check_status! if the waitpid call returns because the process has stopped).
kill! Kills the background process being run.
trap_output[=?] Set/get the trap_output flag.
trap_output_on! Set standard output trapping on. Has the side effect of turning async off.
trap_output_off! Set standard output trapping off.
async[=?] Set/get the async flag.
async_on! Set asynchronous mode on. Has the side effect of turning trap_output off.
async_off! Set asynchronous mode off.
wait! Perform waitpid(2) system call to wait for shell process to terminate, or to clear defunct shell process id from process table. Updates status and pid. If the process terminated, its end actions are executed. Could be used after termination of an asynchronous shell if "check_status!" is not done.
check_status! Does a non-blocking waitpid on the asynchronous shell process. Updates status and pid. If the process terminated, its end actions are executed. If this message is sent to the class, it is forwarded to all of the instances.
end_actions[=+?] Modify the list of actions that are performed upon shell termination. Analogous to "tick_actions[=+?]" for an actions object.
implements the command string: spline -a < "10 40 20 50 30" | sed '2,$s/^/,' | sed 's/ /,/g'
plot_data new: data;
shell new: sh command="rsh snowbird 'spline -a'" std_input="10 40 20 50 30" ;
sh std_input=[sh do!] -- execute command and return standard output command="sed '2,$s/^/,/'" ;
sh std_input=[sh do!] command="sed 's/ /,/g'" ;
string new: s = "data xy_data=(" + [sh do!] + ");" ;
parser parse: s;
/* * Install the handler */ signal_handler install:("SIGCHLD",sigchld_handler);
/* * For illustrative purposes, we can set the signal_handler to * act immediately rather than wait for the next msg_send, since, * when this script terminates, lymb will be idle waiting for user * input. Normally, we would keep deferred mode set. */ signal_handler set_immediate:`SIGCHLD';
shell new:sh1 command=`sleep 10' async_on! end_actions=`! sh1 done'
new:sh2 command=`sleep 11' end_actions=`! sh2 done' new:sh3 command=`sleep 12' end_actions=`! sh3 done' new:sh4 command=`sleep 13' end_actions=`! sh4 done' new:sh5 command=`sleep 14' end_actions=`! sh5 done' ;
sh1 do!; sh2 do!; sh3 do!; sh4 do!; sh5 do!;