コマンドの出力を処理する必要がある一般的な Lisp プログラムを作成しています。ただし、結果を別の関数で使用しようとすると、戻り値として NIL しか取得できません。
コマンドを実行するために使用する関数は次のとおりです。
(defun run-command (command &optional arguments)
(with-open-stream (pipe
(ext:run-program command :arguments arguments
:output :stream :wait nil))
(loop
:for line = (read-line pipe nil nil)
:while line :collect line)))
単独で実行すると、次のようになります。
CL-USER> (run-command "ls" '("-l" "/tmp/test"))
("-rw-r--r-- 1 petergil petergil 0 2011-06-23 22:02 /tmp/test")
ただし、関数を介して実行すると、NIL のみが返されます。
(defun sh-ls (filename)
(run-command "ls" '( "-l" filename)))
CL-USER> (sh-ls "/tmp/test")
NIL
関数で結果を使用するにはどうすればよいですか?