I am writing a common lisp program that needs to handle the output of a command. However, when I try to use the results in another function, I only get a NIL as return-value.
Here is the function I use to run commands:
(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)))
Which, when run by itself gives:
CL-USER> (run-command "ls" '("-l" "/tmp/test"))
("-rw-r--r-- 1 petergil petergil 0 2011-06-23 22:02 /tmp/test")
However, when I run it through a function, only NIL is returned:
(defun sh-ls (filename)
(run-command "ls" '( "-l" filename)))
CL-USER> (sh-ls "/tmp/test")
NIL
How can I use the results in my functions?
Try this:
(defun sh-ls (filename)
(run-command "ls" (list "-l" filename)))
The '("-l" filename) is quoting the list, AND the symbol 'filename', rather than evaluating filename.