Class process provides an interface to other (Unix) processes. This may be used for various purposes:
synchronous and asynchronous.
In the first case the output of the process is explicitly read from the process
object (see process stream<-read_line’.
In the latter case, a message
object is associated with the process that will be invoked
asynchronously when output from the process becomes available (see stream->input_message).
When PCE is killed, it will first terminate all processes. See also
pce->exit_message.
->initialise
and process->open.
Note that the arguments are not interpreted by a shell.
|int*exit()
and the value is the argument passed to exit.<-environment)
for the child process. Either the get- or the send-method will create a
sheet mapping environment variable named onto values and fill the slot
with this sheet. Send changes the sheet's content.
If this variable is set on process->open,
the child will be passed these environment variables. For example, to
start tex myfile.tex with TEXINPUTS set to’../TeXmacros:/usr/local/lib/tex/macros’:
?- new(P, process(tex, 'myfile.tex')),
send(P, environment, 'TEXINPUTS',
'../TeXmacros:/usr/local/lib/tex/macros'),
send(P, input_message,
message(@pce, write, @arg1)),
send(P, open).
<->record_separator
and‘process
stream<->input_message).<->record_separator
equals @nil,
data is passed as soon as it is available. In this case it is not clear
if and how long chunks of data are split over multiple messages.
Otherwise, the input data will be split according to stream<->record_separator
and this message will be invoked for each complete record.
execvp() and thus uses the executable search-path. Note
that this is only the plain name. The arguments are stored in process<-arguments.
|int*Defaults: The default is regex('\n'), which
implies the input if split into (complete) lines.
exit()
exit(). @receiver
is bound to the process
object.
@arg1 gives the
name of the signal or the exit status (integer).
Note that input is dealt with through the event mechanism of X-windows, while status changes to the process are dealt with using Unix signals. This implies the process can signal it has terminated, while their is still input available from it.
<-pid
equals @nil)
or the process is not connected to a terminal (process<->use_tty
equals @off).
When a process is connected by means of a tty, the tty might perform input and output translations for the process. Notably control-characters send to the process will be translated as usual. Pipes to not do any translations.
Defaults: @on
process ->exitedexit()status of the process (0=success)process ->killedName of the signal. See process ->kill.
->open.
The first argument is used to set process<-name.
A vector created from the remaining arguments is stored in process<-arguments.
Note that the command, nor the arguments are interpreted (like the Unix shell does). The call
new(P, process('awk -f script.awk')).
will search for a file names awk -f script.awk, which of
course it can't find. Instead, use
new(P, process(awk, '-f', 'script.awk')).
or
new(P, process('/bin/sh', '-c', 'awk -f script.awk')).
|name]SIGTERM ==> term SIGINT ==> int SIGHUP ==> hup
->initialise.
If the process is already running, nothing happens.
When process<->use_tty
equals @on, a
pseudo-tty is allocated, the PCE forks a new process, connecting
standard (error) I/O to this pseudo-terminal. If process<-environment
is given, the environment of the child is manipulated accordingly. If process<-directory
is given the child will change working directory. Finally the child
execvp's (see man execvp()) using the
process<-name
and process<-arguments
from the process
object.
When process<->use_tty
equals @off,
two pipes are created, after which PCE forks. stdin of the process is
associated with one of these pipes, stdout and stderror with the other.
The command is started the same way as with process<->use_tty @on.
|int*-record_separator->kill’s
the process.<-use_tty
variable. Checks that the process is not currently running.