我正在编写一个需要处理命令输出的常见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)))
Run Code Online (Sandbox Code Playgroud)
哪个,当它自己运行时给出:
CL-USER> (run-command "ls" '("-l" "/tmp/test"))
("-rw-r--r-- 1 petergil petergil 0 2011-06-23 22:02 /tmp/test")
Run Code Online (Sandbox Code Playgroud)
但是,当我通过函数运行它时,只返回NIL:
(defun sh-ls (filename)
(run-command "ls" '( "-l" filename)))
CL-USER> (sh-ls "/tmp/test")
NIL
Run Code Online (Sandbox Code Playgroud)
如何在我的函数中使用结果?
试试这个:
(defun sh-ls (filename)
(run-command "ls" (list "-l" filename)))
Run Code Online (Sandbox Code Playgroud)
'(" - l"filename)引用列表,并引用符号'filename',而不是评估文件名.