Executing a shell command from Common Lisp

ASDF provides a RUN-SHELL-COMMAND that works with many Common Lisp implementations including ABCL, Allegro CL, CLISP, Clozure CL, ECL, GCL, LispWorks, SBCL, CMU, XCL and SCL.

It takes a control string and a list of arguments like FORMAT, and synchronously executes the result using a Bourne-compatible shell. Capture output by binding an optional stream.


You can consider using Trivial-shell (url)

(trivial-shell:shell-command "echo foo")

shell-command returns output, so you can assign it to a variable.

In asdf.lisp file you can read:

;;;; We probably should move this functionality to its own system and deprecate

;;;; use of it from the asdf package. However, this would break unspecified

;;;; existing software, so until a clear alternative exists, we can't deprecate

;;;; it, and even after it's been deprecated, we will support it for a few

;;;; years so everyone has time to migrate away from it. -- fare 2009-12-01


Nowadays I would use uiop:run-program, where uiop stands for "universal input output" and is a compatibility layer provided by asdf3, formerly known as asdf/driver. As has been said asdf:run-shell-command is obsolete and uiop inherits many features of other libraries such as trivial-shell.

UIOP readme


ITA has released inferior-shell under their QITAB umbrella project.

Some links of possible interest :

  • http://common-lisp.net/gitweb?p=projects/qitab/inferior-shell.git
  • http://common-lisp.net/projects/qitab/
  • http://cliki.net/inferior-shell

A git repository is currently hosted at common-lisp.net :

git clone git://common-lisp.net/projects/qitab/inferior-shell.git