Common lisp 如何修改此代码以支持CCL?

Common lisp 如何修改此代码以支持CCL?,common-lisp,ccl,Common Lisp,Ccl,似乎没有ANSI标准的方法来执行外部程序并获得其输出,如下SBCL特殊代码所示: (defmacro with-input-from-program ((stream program program-args environment) &body body) "Creates an new process of the specified by PROGRAM using PROGRAM-ARGS as a list of

似乎没有ANSI标准的方法来执行外部程序并获得其输出,如下SBCL特殊代码所示:

(defmacro with-input-from-program ((stream program program-args environment)
                               &body body)
"Creates an new process of the specified by PROGRAM using
 PROGRAM-ARGS as a list of the arguments to the program. Binds the
 stream variable to an input stream from which the output of the
 process can be read and executes body as an implicit progn."
#+sbcl
(let ((process (gensym)))
    `(let ((,process (sb-ext::run-program ,program
                                      ,program-args
                                      :output :stream
                                      :environment ,environment
                                      :wait nil)))
   (when ,process
     (unwind-protect
          (let ((,stream (sb-ext:process-output ,process)))
            ,@body)
       (sb-ext:process-wait ,process)
       (sb-ext:process-close ,process))))))
以下CCL代码报告“错误:值#不是预期的类型(并且CCL::BINARY-STREAM INPUT-STREAM)”

我对CCL知之甚少。我想知道如何修改此代码以支持CCL

任何建议都将不胜感激

您应该使用

Triple shell是底层操作系统的一个简单的独立于平台的接口

显然不允许您想要的内容(它同步执行外部命令并返回整个输出)

您可以查看CCL的
运行程序
。见:

  • )
  • (这是一个与您的问题类似的问题)
  • (在上面问题的一个答案中建议)由Quicklisp支持,它似乎对执行外部程序有更好的支持

我使用Linux Mint 12 64位上的CCL 64和
尝试了您的代码(从程序输入(流“ls”“nil”)(循环k=(读取行流nil nil),然后(读取行流nil nil),而k执行(打印k))
并且它完成了我预期的操作(列出当前目录中的文件)。也许您应该提供生成您提到的错误的代码?使用宏(也是CCL 64,Mint 12 64位)尝试
(使用程序输入(流“ls”“nil)(读取字节流))
失败,并显示您提供的消息。因此,解释似乎是您试图从字符流中读取字节。
 #+clozure
 (let ((process (gensym)))
  `(let ((,process (ccl:run-program "/bin/sh" (list "-c" (namestring ,program))
                                    :input nil :output :stream :error :stream
                                    :wait nil)))
   (when ,process
     (unwind-protect
          (let ((,stream (ccl::external-process-output-stream ,process)))     
            ,@body)
       ;(ccl:process-wait (ccl:process-whostate ,process) nil)
       (close (ccl::external-process-output-stream ,process))
       (close (ccl::external-process-error-stream ,process))))))