Common Lisp 中是否存在运行外部程序的标准方法?
在 clisp 中,以下代码有效:
(defun hit-history () (shell "tail ssqHitNum.txt"))
但是,在 Clozure CL 中,不支持 shell
函数!
In clisp, the following code works:
(defun hit-history () (shell "tail ssqHitNum.txt"))
However, in Clozure CL, the shell
function is not supported!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
不,没有标准的方法,但是有一些库为重要的实现提供了此功能。例如,Quicklisp 中提供了 trivial-shell,它提供了
shell-command
。 (我实际上并没有测试它,但它属于推荐库之一href="http://www.cliki.net/index" rel="nofollow noreferrer">CLiki。)还有外部程序。更新:正如 Ehvince 指出的那样,inferior-shell 现在似乎更受欢迎在评论和他自己的回答中。您还可以使用读取时条件来使不同的实现使用各自的功能来执行此操作。
CCL有
ccl:run-program
,例如:No, there is no standard way, but there are libraries which provide this functionality for the important implementations. For example, there's trivial-shell available in Quicklisp, which provides
shell-command
. (I didn't actually test it, but its among the recommended libraries on CLiki.) There is also external-program. Update: inferior-shell seems to be prefered these days, as Ehvince points out in a comment and his own answer.You could also use read-time conditionals to make different implementations use their respective functionality to do this.
CCL has
ccl:run-program
, for example:是的,UIOP,ASDF 的一部分,应该包含在所有现代中实施。
uiop:run-program
uiop:launch-program
例如
,或者
您可以发送输入并读取输出。
这里有更多解释:https://lispcookbook。 github.io/cl-cookbook/os.html#running-external-programs
trivial-shell
已弃用并替换为 inferior-shell,内部使用可移植的 uiop 的run-program
(同步),所以我们可以使用它。Yes, with UIOP, part of ASDF, that should be included in all modern implementations.
uiop:run-program
uiop:launch-program
So for example
or
where you can send input and read output.
They are more explained here: https://lispcookbook.github.io/cl-cookbook/os.html#running-external-programs
trivial-shell
is deprecated and replaced by inferior-shell, which internally uses the portable uiop'srun-program
(synchronous), so we can use just that.当我学习lisp p123时,我在ccl(clozure)中运行成功
i run success in ccl(clozure),when study land of lisp p123
下面显示了从 common lisp 中调用 wget 的示例:
https://diasp.eu/posts/1742240
这是代码:
The following shows an example of calling wget from within common lisp:
https://diasp.eu/posts/1742240
Here's the code:
看一下
inferior-shell
包。(通过全能的
quicklisp
包管理器获取它。)如果您有互联网,这可以在解释器中运行:
Have a look at the
inferior-shell
package.(Get it via the almighty
quicklisp
package manager.)This works in the interpreter, if you have internet:
CL21 定义了简单的方法:
然后使用
run-process
或使用 #` reader 宏:或者
源代码显示了 SBCL 和 CCL 的实现。
CL21 defines simple methods:
Then either with
run-process
or with the #` reader macro:or
The source shows implementation for SBCL and CCL.