使用gnu clisp运行shell命令

Pau*_*han 4 lisp clisp stream

我正在尝试为clisp创建一个像这样工作的"系统"命令

(setq result (system "pwd"))

;;now result is equal to /my/path/here
Run Code Online (Sandbox Code Playgroud)

我有这样的事情:

(defun system (cmd)
 (ext:run-program :output :stream))
Run Code Online (Sandbox Code Playgroud)

但是,我不确定如何将流转换为字符串.我已经多次回顾了hyperspec和google.

编辑:使用Ranier的命令并使用with-output-to-stream,

(defun system (cmd)
  (with-output-to-string (stream)
    (ext:run-program cmd :output stream)))
Run Code Online (Sandbox Code Playgroud)

然后试着跑grep,这是我的道路......

[11]> (system "grep")

*** - STRING: argument #<OUTPUT STRING-OUTPUT-STREAM> should be a string, a
      symbol or a character
The following restarts are available:
USE-VALUE      :R1      Input a value to be used instead.
ABORT          :R2      Abort main loop
Break 1 [12]> :r2
Run Code Online (Sandbox Code Playgroud)

Rai*_*wig 5

像这样的东西?

版本2:

(defun copy-stream (in out)
   (loop for line = (read-line in nil nil)
         while line
         do (write-line line out)))

(defun system (cmd)
  (with-open-stream (s1 (ext:run-program cmd :output :stream))
    (with-output-to-string (out)
      (copy-stream s1 out))))


[6]> (system "ls")
"#.emacs#
Applications
..."
Run Code Online (Sandbox Code Playgroud)