2011-06-23 4 views
2

私はコマンドの出力を処理する必要のある共通のlispプログラムを書いています。しかし、別の関数で結果を使用しようとすると、返り値としてNILしか得られません。ここで共通のlispでシェルスクリプトからstdoutを使用する

は、私は、コマンドを実行するために使用する機能です。単独で実行、

(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 

どのように私の機能に結果を使用できますか?

答えて

7

このお試しください:

(defun sh-ls (filename) 
     (run-command "ls" (list "-l" filename))) 

を「( "-l" filename)は、リストを引用し、シンボルれる 'ファイル名' のではなく、ファイル名を評価します。

+0

これは動作します。すばらしいです! – petergil

4

またsexpr前に `バッククォートを使用することができると、ファイル名の前にそれを評価する:

(defun sh-ls (filename) 
     (run-command "ls" `("-l" ,filename))) 
関連する問題