A patch is now available (by running sys:update-allegro) that provides better integration between Lisp and native operating system resources. The documentation on this new facility has been added to the Operating System Interface (doc/os-interface.htm) document. See particularly Appendix 1: Operating System Interface Functionality in that document.
In a nutshell, the new facility offers an interface to many of the system calls and library routines documented in chapters 2 and 3 of the UNIX manual. Some, but not all, of the functionality is available on Microsoft Windows. This is somewhat of a philosophical departure for us: we strive to make each and every feature be available on all the platforms on which Allegro Common Lisp is supported (16 platforms). We felt for Lisp to be competitive in certain areas we needed to break this rule.
In addition to the interface to system services, we have also created three new process manipulation operators. They can be used when input to and/or output from a subprocess is needed. Below are some examples using the new operators command-output, with-command-output, and with-command-io. One important thing to note about these new, higher-level process operators: they handle the reaping of the subprocess exit status (use of sys:reap-os-subprocess is not needed) as well as closing the streams associated with input to and output from the subprocess. When using excl:run-shell-command these tasks are left to the user.
The new functionality is present in the osi module and excl.osi package.
Here are some examples of the new subprocess manipulation operators:
cl-user(1): (require :osi) ;; fast-loading osi.fasl t cl-user(2): (use-package :excl.osi) t ;; line at a time or all at once, using the :whole keyword argument: cl-user(3): (command-output "who") ("mikel pts/0 Oct 3 15:38 (ultra)" "layer pts/1 Oct 22 10:26 (crikey)") nil 0 cl-user(4): (command-output "who" :whole t) "mikel pts/0 Oct 3 15:38 (ultra) layer pts/1 Oct 22 10:26 (crikey) " nil 0 cl-user(5): (command-output "cat" :input "this is multi-line input for the cat program") ("this is multi-line" "input for the cat program") nil 0 cl-user(6): (with-command-io ("cat") (:input (stream) (format stream "cat this~%") (format stream "cat this, too~%")) (:output (line) (format t "output: ~a~%" line))) output: cat this output: cat this, too 0 cl-user(7): (with-command-output (line "cat /etc/issue") (format t "output: ~a~%" line)) output: output: Red Hat Linux release 6.0 (Hedwig) output: Kernel 2.2.19 on an i686 output: 0 cl-user(8):
cl-user(6): (setq temp-file (with-open-temp-file (stream "/tmp/tempXXXXXX") (format stream "this is temp stuff~%"))) "/tmp/tempERdYgm" cl-user(7): (file-contents temp-file) "this is temp stuff " cl-user(8): (delete-file temp-file) t cl-user(9): (getgroups) (50 10 51 59 100) cl-user(10): (getpriority *prio-process* (getpid)) 0 cl-user(11): (setpriority *prio-process* (getpid) 10) ;; lower the process prioirity t cl-user(12): (getpriority *prio-process* (getpid)) 10 cl-user(13): (setpriority *prio-process* (getpid) 0) ;; raise again Error: setpriority failed: Permission denied [errno=13]. [condition type: syscall-error] Restart actions (select using :continue): 0: Return to Top Level (an "abort" restart). 1: Abort entirely from this process.  cl-user(14): ;; only `root' can raise priorities... cl-user(20): (openlog "foo" (logior *log-perror* *log-pid*) *log-user*) t cl-user(21): (syslog *log-info* "foo has started") foo: foo has started t cl-user(22): ;; the end of /var/log/messages now has the following: ;; Nov 7 15:37:17 killer foo: foo has started
|Copyright © 2016 Franz Inc., All Rights Reserved | Privacy Statement||