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

时间:2012-02-05 01:27:48

标签: 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 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代码报告“ERROR:value#不是预期类型(AND CCL :: BINARY-STREAM INPUT-STREAM)”

 #+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))))))

我知道CCL很少。我想知道如何修改此代码以支持CCL?

任何建议都表示赞赏!

2 个答案:

答案 0 :(得分:4)

显然trivial-shell:shell-command不能完全允许你想要的东西(它同步执行外部命令并返回整个输出)。

您可以查看CCL' run-program。参见:

答案 1 :(得分:1)

您应该使用trivial-shell

  

Trivial shell是底层操作系统的简单平台独立接口。