在 clisp 中,以下代码有效:
(defun hit-history () (shell "tail ssqHitNum.txt"))
但是,在 Clozure CL 中,shell
不支持该功能!
在 clisp 中,以下代码有效:
(defun hit-history () (shell "tail ssqHitNum.txt"))
但是,在 Clozure CL 中,shell
不支持该功能!
不,没有标准的方法,但是有一些库为重要的实现提供了这个功能。例如,Quicklisp中有 trivial-shell 可用,它提供shell-command
. (我实际上并没有测试它,但它是CLiki上推荐的库之一。)还有外部程序。更新:这些天似乎更喜欢劣质外壳,正如 Ehvince 在评论和他自己的回答中指出的那样。
您还可以使用读取时条件来使不同的实现使用它们各自的功能来执行此操作。
CCL 有ccl:run-program
,例如:
CL-USER> (run-program "whoami" '() :output *standard-output*)
foobar
#<EXTERNAL-PROCESS (whoami)[NIL] (EXITED : 0) #xC695EA6>
是的, UIOP 是ASDF的一部分,应该包含在所有现代实现中。
uiop:run-program
uiop:launch-program
所以例如
(uiop:run-program (list "firefox" "http:url") :output t)
或者
(defparameter *shell* (uiop:launch-program "bash" :input :stream :output :stream))
您可以在其中发送输入和读取输出。
他们在这里得到更多解释: https ://lispcookbook.github.io/cl-cookbook/os.html#running-external-programs
trivial-shell
已被弃用并替换为lower -shell,它在内部使用可移植的uiop (run-program
同步),所以我们可以使用它。
(defun dot->png (fname thunk)
(with-open-file (*standard-output*
fname
:direction :output
:if-exists :superseded)
(funcall thunk))
(ccl:run-program "dot" (list "-Tpng -O" fname))
)
当我学习 lisp p123 的土地时,我在 ccl(clozure) 中取得了成功
下面显示了从 common lisp 中调用 wget 的示例:
https://diasp.eu/posts/1742240
这是代码:
(sb-ext:run-program "/usr/bin/wget" '("-O" "<path-to-output-file>" "<url-link>") :output *standard-output*)
看看inferior-shell
包装。
(通过全能的quicklisp
包管理器获取它。)
如果您有互联网,这适用于口译员:
(require 'inferior-shell)
(inferior-shell:run/s '(curl icanhazip.com))
CL21 定义了简单的方法:
(in-package :cl21-user)
(use-package :cl21.process)
然后使用run-process
或使用 #` 阅读器宏:
(run-process '("ls" "-l"))
;-> total 0
; drwxrwxrwt 5 root wheel 170 Nov 1 18:00 Shared
; drwxr-xr-x+ 174 nitro_idiot staff 5916 Mar 5 21:41 nitro_idiot
;=> #<PROCESS /bin/sh -c ls -l /Users (76468) EXITED 0>
或者
#`ls -l /Users`
;=> "total 0
; drwxrwxrwt 5 root wheel 170 Nov 1 18:00 Shared
; drwxr-xr-x+ 174 nitro_idiot staff 5916 Mar 5 21:41 nitro_idiot
; "
; ""
; 0
源代码显示了 SBCL 和 CCL 的实现。