[info-mcl] MCL Contribution: Execute shell commands
terje
terje at in-progress.com
Fri Oct 19 02:59:21 CDT 2007
I have enclosed a new contribution to execute shell commands from
MCL. For example, this will list the current directory:
(execute-shell-command "ls")
Importantly, using this contribution to execute shell commands DOES
NOT BLOCK MCL during execution of the shell commands, thanks to the
use of KQueue to get notified when new characters are available for
input from the process. You may for example execute the following
without hanging MCL:
(execute-shell-command "sleep 5")
Alternatively, provide an optional stream to write the output. Here
is an example that writes the calendar of the current month typically
to the Listener:
(execute-shell-command "cal" :output-stream *debug-io*)
There is also a stream for I/O from the BSD process executing the
shell command. Hence you can write code like this:
(with-open-stream (ps (popen "cal"))
(loop
for c = (read-char ps nil)
while c
do (write-char c *debug-io*)))
Note that Popen requires the KQueue contribution I sent in the
previous post.
-- Terje Norderhaug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: popen.lisp
Type: application/applefile
Size: 579 bytes
Desc: not available
URL: <http://clozure.com/pipermail/info-mcl/attachments/20071019/d8bc3219/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: popen.lisp
Type: application/octet-stream
Size: 8703 bytes
Desc: not available
URL: <http://clozure.com/pipermail/info-mcl/attachments/20071019/d8bc3219/attachment.obj>
More information about the info-mcl
mailing list