我正在编写一个需要处理命令输出的通用 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
如何在我的函数中使用结果?