| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.7.3 Process support
Bigloo provides access to Unix-like processes as first class objects. The implementation and this documentation are to a great extent copies of the STk [Gallesio95] process support. Basically, a process contains four informations: the standard Unix process identification (aka PID) and the three standard files of the process.
- bigloo procedure: run-process command arg…
-
run-processcreates a new process and run the executable specified in command. The arg correspond to the command line arguments. When is process completes its execution, non pipe associated ports are automatically closed. Pipe associated ports have to be explicitly closed by the program. The following values of p have a special meaning:-
input:permits to redirect the standard input file of the process. Redirection can come from a file or from a pipe. To redirect the standard input from a file, the name of this file must be specified afterinput:. Use the special keywordpipe:to redirect the standard input from a pipe. -
output:permits to redirect the standard output file of the process. Redirection can go to a file or to a pipe. To redirect the standard output to a file, the name of this file must be specified afteroutput:. Use the special keywordpipe:to redirect the standard output to a pipe. -
error:permits to redirect the standard error file of the process. Redirection can go to a file or to a pipe. To redirect the standard error to a file, the name of this file must be specified aftererror:. Use the special keywordpipe:to redirect the standard error to a pipe. -
wait:must be followed by a boolean value. This value specifies if the process must be ran asynchronously or not. By default, the process is run asynchronously (i.e.wait:if#f). -
host:must be followed by a string. This string represents the name of the machine on which the command must be executed. This option uses the external commandrsh. The shell variablePATHmust be correctly set for accessing it without specifying its absolute path. -
fork:must be followed by a boolean value. This value specifies if the process must substitute the current execution. That is, if the value is#ta new process is spawned otherwise, the current execution is stopped and replaced by the execution ofcommand. It defaults to#t. -
env:must be followed by a string of the formvar=val. This will bound an environment variable in the spawned process. Arun-processcommand may contain severalenv:arguments. The current variables of the current process are also passed to the new process.
The following example launches a process which execute the Unix command
lswith the arguments-land/bin. The lines printed by this command are stored in the filetmp/X.(run-process "ls" "-l" "/bin" output: "/tmp/X")
The same example with a pipe for output:
(let* ((proc (run-process "ls" "-l" "/bin" output: pipe:)) (port (process-output-port proc))) (let loop ((line (read-line port))) (if (eof-object? line) (close-input-port port) (begin (print line) (loop (read-line port))))))One should note that the same program can be written with explicit process handling but making use of the
|notation foropen-input-file.(let ((port (open-input-file "| ls -l /bin"))) (let loop ((line (read-line port))) (if (eof-object? line) (close-input-port port) (begin (print line) (loop (read-line port))))))Both input and output ports can be piped:
(let* ((proc (run-process "/usr/bin/dc" output: pipe: input: pipe:)) (inport (process-input-port proc)) (port (process-output-port proc))) (fprint inport "16 o") (fprint inport "16 i") (fprint inport "10") (fprint inport "10") (fprint inport "+ p") (flush-output-port inport) (let loop ((line (read-line port))) (if (eof-object? line) (close-input-port port) (begin (print line) (loop (read-line port)))))) -| 20Note: The call to
flush-output-portis mandatory in order to get thedcprocess to get its input characters.Note: Thanks to Todd Dukes for the example and the suggestion of including it this documentation.
-
- bigloo procedure: process-alive? process
Returns
#tif process is currently running, otherwise returns#f.
- bigloo procedure: close-process-ports command arg…
Close the three ports associated with a process. In general the ports should not be closed before the process is terminated.
- bigloo procedure: process-pid process
Returns an integer value which represents the Unix identification (PID) of the process.
- bigloo procedure: process-input-port process
- bigloo procedure: process-output-port process
- bigloo procedure: process-error-port process
Return the file port associated to the standard input, output and error of process otherwise returns
#f. Note that the returned port is opened for reading when callingprocess-output-portorprocess-error-port. It is opened for writing when callingprocess-input-port.
- bigloo procedure: process-wait process
This function stops the current process until process completion. This function returns
#fwhen process is already terminated. It returns#totherwise.
- bigloo procedure: process-exit-status process
This function returns the exit status of process if it is has finished its execution. It returns
#fotherwise.
- bigloo procedure: process-send-signal process s
Sends the signal whose integer value is s to process. Value of s is system dependent. The result of
process-send-signalis undefined.
- bigloo procedure: process-kill process
This function brutally kills process. The result of
process-killis undefined.
- bigloo procedure: process-stop process
- bigloo procedure: process-continue process
Those procedures are only available on systems that support job control. The function
process-stopstops the execution of process andprocess-continueresumes its execution.
- bigloo procedure: process-list
This function returns the list of processes which are currently running (i.e. alive).
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on October 23, 2011 using texi2html 5.0.
