5. Bigloo -- Standard Library 5.8 Process support

Browsing
Home: | Bigloo A ``practical Scheme compiler'' for Bigloo version 2.5a April 2002
Previous chapter: | Core Language
Next chapter: | Pattern Matching
Standard Library
    5.1 Scheme Library
    5.2 Input and output
    5.3 Structures and Records
    5.4 Serialization
    5.5 Bit manipulation
    5.6 Hash Tables
    5.7 System programming
    5.8 Process support
    5.9 Socket support
    5.10 Posix Regular Expressions
Chapters
    Copyright
    Acknowledgements
    1. Table of contents
    2. Overview of Bigloo
    3. Modules
    4. Core Language
    5. Standard Library
    6. Pattern Matching
    7. Object System
    8. Threads
    9. Regular parsing
    10. Lalr(1) parsing
    11. Errors and Assertions
    12. Eval and code interpretation
    13. Macro expansion
    14. Command Line Parsing
    15. Explicit typing
    16. The C interface
    17. The Java interface
    18. Bigloo Libraries
    19. SRFIs
    20. DSSSL support
    21. Compiler description
    22. User Extensions
    23. Bigloo Development Environment
    24. Global Index
    25. Library Index
    Bibliography
| 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.
run-process command arg... | bigloo procedure
`run-process` creates 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 after `input:`. Use the special keyword `pipe:` 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 after `output:`. Use the special keyword `pipe:` 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 after `error:`. Use the special keyword `pipe:` to redirect the standard error to a pipe. `wait:` must be followed by a boolean value. This value specifies if the process must be run 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 command `rsh`. The shell variable `PATH` must 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 `#t` a new process is spawned otherwise, the current execution is stopped and replaced by the execution of `command`. `env:` must be followed by a string of the form ``var`=`val``. This will bound an environment variable in the spawned process. A `run-process` command may contain several `env:` 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 `ls` with the arguments `-l` and `/bin`. The lines printed by this command are stored in the file `tmp/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 not that the same program can be written with explicit process handling but making use of the `|` notation for `open-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))))))
process? obj | bigloo procedure
Returns `#t` if `obj` is a process, otherwise returns `#f`.
process-alive? process | bigloo procedure
Returns `#t` if `process` is currently running, otherwise returns `#f`.
process-pid process | bigloo procedure
Returns an integer value which represents the Unix identification (PID) of the `process`.
process-input-port process | bigloo procedure
process-output-port process | bigloo procedure
process-error-port process | bigloo procedure
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 calling `process-output-port` or `process-error-port`. It is opened for writing when calling `process-input-port`.
process-wait process | bigloo procedure
This function stops the current process until `process` completion. This function returns `#f` when `process` is already terminated. It returns `#t` otherwise.
process-exit-status process | bigloo procedure
This function returns the exit status of `process` if it is has finished its execution. It returns `#f` otherwise.
process-send-signal process s | bigloo procedure
Sends the signal whose integer value is `s` to `process`. Value of `s` is system dependent. The result of `process-send-signal` is undefined.
process-kill process | bigloo procedure
This function brutally kills `process`. The result of `process-kill` is undefined.
process-stop process | bigloo procedure
process-continue process | bigloo procedure
Those procedures are only available on systems that support job control. The function `process-stop` stops the execution of `process` and `process-continue` resumes its execution.
process-list | bigloo procedure
This function returns the list of processes which are currently running (i.e. alive).

This Scribe page has been generated by `scribeinfo`.
Last update Thu Apr 25 09:40:15 2002