3

似乎没有 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 代码报告“错误:值 # 不是预期类型(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?

任何建议表示赞赏!

4

2 回答 2

4

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

您可以查看 CCL 的run-program. 看:

于 2012-02-05T12:24:18.693 回答
1

你应该使用trivial-shell

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

于 2012-02-05T10:29:16.693 回答