加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用gnu clisp运行shell命令

发布时间:2020-12-15 22:11:46 所属栏目:安全 来源:网络整理
导读:我正在尝试为clisp创建一个像这样工作的“系统”命令 (setq result (system "pwd"));;now result is equal to /my/path/here 我有这样的事情: (defun system (cmd) (ext:run-program :output :stream)) 但是,我不确定如何将流转换为字符串.我已经多次回顾了
我正在尝试为clisp创建一个像这样工作的“系统”命令

(setq result (system "pwd"))

;;now result is equal to /my/path/here

我有这样的事情:

(defun system (cmd)
 (ext:run-program :output :stream))

但是,我不确定如何将流转换为字符串.我已经多次回顾了hyperspec和google.

编辑:使用Ranier的命令并使用with-output-to-stream,

(defun system (cmd)
  (with-output-to-string (stream)
    (ext:run-program cmd :output stream)))

然后尝试运行grep,这是我的道路……

[11]> (system "grep")

*** - STRING: argument #<OUTPUT STRING-OUTPUT-STREAM> should be a string,a
      symbol or a character
The following restarts are available:
USE-VALUE      :R1      Input a value to be used instead.
ABORT          :R2      Abort main loop
Break 1 [12]> :r2

解决方法

像这样的东西?

版本2:

(defun copy-stream (in out)
   (loop for line = (read-line in nil nil)
         while line
         do (write-line line out)))

(defun system (cmd)
  (with-open-stream (s1 (ext:run-program cmd :output :stream))
    (with-output-to-string (out)
      (copy-stream s1 out))))


[6]> (system "ls")
"#.emacs#
Applications
..."

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读