在clisp中,以下的代码是有效的:
(defun hit-history () (shell "tail ssqHitNum.txt"))
然而,在Clozure CL中,shell
函数不被支持!
(defun hit-history () (shell "tail ssqHitNum.txt"))
然而,在Clozure CL中,shell
函数不被支持!
shell-command
。(我实际上没有测试过,但它是CLiki上的recommended libraries之一。)还有external-program。更新:inferior-shell似乎是这些天更受欢迎的选择,正如Ehvince在评论和他自己的答案中指出的那样。ccl:run-program
:CL-USER> (run-program "whoami" '() :output *standard-output*)
foobar
#<EXTERNAL-PROCESS (whoami)[NIL] (EXITED : 0) #xC695EA6>
是的,使用ASDF的一部分UIOP,应该包含在所有现代实现中。
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
已经过时,被inferior-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之地》的第123页时,在ccl(Clozure)中成功运行了程序。
(sb-ext: run-program "/usr/bin/dot" (list "-Tpng" "-O" fname)))
。 - dpritchinferior-shell
包。 (通过万能的 quicklisp
包管理器获取。)(require 'inferior-shell)
(inferior-shell:run/s '(curl icanhazip.com))
https://diasp.eu/posts/1742240
这里是代码:(sb-ext:run-program "/usr/bin/wget" '("-O" "<path-to-output-file>" "<url-link>") :output *standard-output*)
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的实现。
trivial-shell
库无需快速加载 Quicklisp。此外,我不确定“读取时间条件”的建议背后的原因,因为这正是 trivial-shell 所做的。这就是为什么这些库被称为 trivial-* 的原因。 - Kentrivial-shell
已被弃用,现已被inferior-shell所取代,它简单地使用uioprun-program
(同步)。如需异步,请参阅uiop的launch-program
。 - Ehvince