From: David Wallis
Subject: execute a unix command in cmucl
Date: 
Message-ID: <417F9064.4C0EEEBE@cpom.ucl.ac.uk>
I can't find a way of executing a unix command in cmucl. Is it possible?

e.g.

(system "ls -l")

--
David Wallis, CPOM, Dept. Space & Climate Physics, Pearson Building
University College London, Gower Street, London WC1E 6BT, UK
Tel: +44 (0)20.7679.3740  Fax: +44 (0)20.7679.7883
http://www.cpom.org

From: Edi Weitz
Subject: Re: execute a unix command in cmucl
Date: 
Message-ID: <uvfcwuytl.fsf@agharta.de>
On Wed, 27 Oct 2004 13:11:16 +0100, David Wallis <···@cpom.ucl.ac.uk> wrote:

> I can't find a way of executing a unix command in cmucl. Is it
> possible?
>
> e.g.
>
> (system "ls -l")

RTFM:

  <http://common-lisp.net/project/cmucl/doc/cmu-user/extensions.html#toc46>

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Björn Lindberg
Subject: Re: execute a unix command in cmucl
Date: 
Message-ID: <hcssm80mhjp.fsf@my.nada.kth.se>
David Wallis <···@cpom.ucl.ac.uk> writes:

> I can't find a way of executing a unix command in cmucl. Is it possible?
> 
> e.g.
> 
> (system "ls -l")

You should read the manual as Edi suggested. Apart from that, I have a
couple of convenience functions which may be useful:

(defun run (command &rest args)
  "Runs command with arguments args. Returns the exit code for the
   process."
  (let ((proc (ext:run-program command args)))
    (prog1 (ext:process-exit-code proc)
      (ext:process-close proc))))

(defun shell (string &rest args)
  "Runs string as argument to 'sh -c'. Any remaining arguments are
   used as arguments to FORMAT, so that the string is interpolated by
   FORMAT. If the named argument :shell is given, that shell will be
   used instead of sh. The name of the shell can be given as a string
   or as a symbol."
  (let* ((shell "sh")
         (formatted-string (apply #'format nil string 
                                  (let (flag)
                                    (remove-if (lambda (x) 
                                                 (cond (flag (setf flag nil)
                                                             (setf shell x) t)
                                                       ((eq x :shell) 
                                                        (setf flag t))
                                                       (t nil)))
                                               args)))))
    (run (string-downcase (string shell)) "-c" formatted-string)))

(defmacro with-output-from-program ((stream program args)  &body body)
  (with-gensyms (proc)
    `(let* ((,proc (ext:run-program ,program ,args :output :stream :wait nil))
            (,stream (ext:process-output ,proc)))
      (unwind-protect
           (progn
             ,@body)
        (ext:process-close ,proc)))))

They are a bit rough around the edges, and could surely be generalized
and improved upon, but may nevertheless serve as inspiration, I
hope. In particular, neither of these will print the output from the
command on standard output, which I suspect is what you want.


Bj�rn