在 Common Lisp 中使用 shell 脚本中的 stdout
我正在编写一个需要处理命令输出的 Common 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
如何在函数中使用结果?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
'("-l" filename) 引用列表和符号 'filename',而不是评估文件名。
Try this:
The '("-l" filename) is quoting the list, AND the symbol 'filename', rather than evaluating filename.
您还可以在 sexpr 之前和文件名之前使用反引号 ` 来对其进行评估:
You can also use backquote ` before sexpr and , before filename to evaluate it: