Name

ext:system — Invoke a command using the shell.

Function

(ext:system command)

command

A string

returns

An integer (0-255) with the exit code of the program

Description

This function executes a command in the shell. In Unix systems, typically the environment variable SHELL determines which program will be invoked, while in Windows CMD.EXE is used. The string may thus be any valid command that the shell accepts and in can contain higher level elements such as input/output redirection.

As an example, the following function uses an external editor to modify a lisp file and, if successful, loads the changed sources:

(defun edit (filename)
  (let* ((editor #+windows "notepad.exe"
                 #-windows "/usr/bin/emacs")
    (command (concatenate 'string editor " " filename)))
    (when (zerop (ext:system command))
    (load filename))))