executor

外部の実行可能プログラムを起動するためのライブラリ。
処理系毎の違いを吸収してくれます。

http://www.cliki.net/executor

いまのところ「ドキュメントはソース」かつ対応実装はSBCLのみの様です。

外部コマンドの実行

execute

基本的な機能。パス検索もなし。

(exec:execute "/bin/ls" '("/tmp"))
;; -> /tmpのファイル一覧
;; => 0 ;; commandのexit status


;; 別の書き方
(exec:execute* "/bin/ls" "/tmp")
execute-external

パス検索機能あり。

実行形式ファイルを探すディレクトリをexec:*search-path*にリストで設定します。ロード後には (#p"/bin" #p"/usr/bin")が設定されています。
:outputは起動するコマンドの出力先ポートを指定します。デフォルトはnilで標準出力は破棄されます。tを指定すると*standard-output*が標準出力になります。:captureはコマンドの出力を文字列にして、2つめの戻り値として返します。

(exec:execute-external 'ls '("/tmp") :output t)
;; -> /tmpのファイル一覧
;; => t


(exec:execute-external 'ls '("/tmp") :output :capture)
;; => t
;;    "/tmpのファイル一覧"


(with-output-to-string (port)
	   (exec:execute-external 'ls '("/tmp") :output port))
;; => "/tmpのファイル一覧"
define-executable

exec:execute-externalの実行を行う関数を定義するマクロです。
:outputに:cautureを指定した様に動きます。

(exec:define-executable (ls "ls"))
:: => LS
(ls "/tmp")
;; => t
;;    "/tmpのファイル一覧"

パイプラインの形成

pipeline

基本的な機能。パス検索もなし。

(exec:pipeline '(("/bin/cat" "hoge.txt")
                 ("/usr/bin/grep" "hoge")))
;; -> hoge.txtの中の"hoge"を含む行
;; => 0 ;; commandのexit status


;; 別の書き方
(exec:pipeline* '("/bin/cat" "hoge.txt")
                '("/usr/bin/gerp" "hoge"))
pipe

pipelineを呼び出すマクロ。
なぜかfind-executableでシンボルに対応する実行可能ファイルの登録を行わないと使用できない。

(exec:find-executable 'cat)
;; => #p"/bin/cat"
(exec:find-executable 'grep)
;; => #p"/usr/bin/grep"
(exec:pipe (cat "hoge.txt") (grep "hoge"))
;; -> hoge.txtの中の"hoge"を含む行
;; => 0 ;; commandのexit status

他にも色々関数、マクロはありますが、基本的なところはこんな感じでした。