gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 02:55:38 25 4
gpt4 key购买 nike

似乎没有 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)”

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

感谢任何建议!

最佳答案

显然 trivial-shell:shell-command不允许完全符合您的要求(它同步执行外部命令并返回整个输出)。

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

关于common-lisp - 如何修改此代码以支持 CCL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9146161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com