似乎没有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代码报告“错误: value #不是预期的类型(和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?
欢迎提出任何建议!
发布于 2012-02-05 20:24:19
显然,trivial-shell:shell-command并不完全支持您想要的(它同步执行外部命令并返回整个输出)。
您可以查看CCL的run-program。请参见:
Quicklisp支持
external-program类似的问题(在上面问题中的一个答案中建议),而且它似乎对执行外部程序有更好的支持。发布于 2012-02-05 18:29:17
您应该使用trivial-shell。
普通外壳是一个简单的独立于平台的底层操作系统接口。
https://stackoverflow.com/questions/9146161
复制相似问题