相关疑难解决方法(0)

如何在Steel Bank Common Lisp中处理输入和输出流?

我正在试图弄清楚如何使用我开始的一个程序的输出流,RUN-PROGRAM因此它可以用作另一个程序的输入RUN-PROGRAM(即道德,也许是文字等效的管道).我已经使用了一些组合的尝试:INPUT,:OUTPUT:WAIT关键字参数,但没有我打后一直生产至今.任何提示都会有所帮助; 例如,我将如何ls | grep lisp从shell中做一些事情?

我的一个尝试是

(defun piping-test () 
  (let ((grep-process (run-program "/usr/bin/grep" '("lisp") 
                                  :input :stream 
                                  :output :stream))) 
    (unwind-protect 
        (with-open-stream (s (process-input grep-process)) 
          (let ((ls-process (run-program "/bin/ls" '() 
                                        :output s))) 
            (when ls-process 
              (unwind-protect 
                  (with-open-stream (o (process-output grep-process)) 
                   (loop 
                      :for line := (read-line o nil nil) 
                      :while line 
                      :collect line)) 
               (process-close ls-process))))) 
     (when grep-process (process-close grep-process))))) 
Run Code Online (Sandbox Code Playgroud)

在SLIME REPL中运行它会导致一切都挂起,直到我打破C-c C-c,所以它显然不是正确的事情,但我不知道如何改变它所以它是正确的.

编辑:添加:WAIT NIL到两个RUN-PROGRAM调用,或仅添加到调用grep …

lisp sbcl common-lisp

10
推荐指数
1
解决办法
3237
查看次数

在Common Lisp中读取外部程序的二进制输出

我正在尝试在SBCL中运行外部程序并捕获其输出.输出是二进制数据(png图像),而SBCL坚持将其解释为字符串.

我试过很多方法,比如

(trivial-shell:shell-command "/path/to/png-generator" :input "some input")

(with-input-from-string (input "some input")
  (with-output-to-string (output)
    (run-program "/path/to/png-generator" () :input input :output output))


(with-input-from-string (input "some input")
  (flexi-streams:with-output-to-sequence (output)
    (run-program "/path/to/png-generator" () :input input :output output))
Run Code Online (Sandbox Code Playgroud)

但我得到的错误就像

Illegal :UTF-8 character starting at byte position 0.
Run Code Online (Sandbox Code Playgroud)

在我看来,SBCL正试图将二进制数据解释为文本并对其进行解码.我该如何改变这种行为?我只对获取八位字节的向量感兴趣.

编辑:由于上面的文字不清楚,我想补充一点,至少在flexi-stream的情况下,流的元素类型是a flexi-streams:octect(这是a (unsigned-byte 8)).我希望至少在这种情况下run-program读取原始字节没有很多问题.相反,我收到了一条消息Don't know how to copy to stream of element-type (UNSIGNED-BYTE 8)

sbcl common-lisp stream

5
推荐指数
1
解决办法
2264
查看次数

如何与SBCL/Common Lisp中的进程输入/输出进行交互

我有一个文本文件,每行一个句子.我想使用hunspell(-s选项)对每行中的世界进行lemmatize.由于我想分别对每行的引理进行处理,因此将整个文本文件提交给hunspell是没有意义的.我需要一个接一个地发送一行,并为每一行提供hunspell输出.

以下是如何处理Steel Bank Common Lisp中的输入和输出流的答案,我能够为hunspell发送一行接一行的整个文本文件但是我无法捕获每行的hunspell输出.如何在发送另一条线之前与发送线路和读取输出的进程进行交互?

我当前读取整个文本文件的代码是

(defun parse-spell-sb (file-in)
  (with-open-file (in file-in)
    (let ((p (sb-ext:run-program "/opt/local/bin/hunspell" (list "-i" "UTF-8" "-s" "-d" "pt_BR") 
                 :input in :output :stream :wait nil)))
      (when p
        (unwind-protect 
          (with-open-stream (o (process-output p)) 
            (loop 
         :for line := (read-line o nil nil) 
         :while line 
         :collect line)) 
          (process-close p))))))
Run Code Online (Sandbox Code Playgroud)

再一次,这段代码为我提供了整个文本文件的hunspell输出.我想分别为每个输入行输出hunspell.

任何的想法?

sbcl common-lisp

5
推荐指数
1
解决办法
2267
查看次数

使用gnu clisp运行shell命令

我正在尝试为clisp创建一个像这样工作的"系统"命令

(setq result (system "pwd"))

;;now result is equal to /my/path/here
Run Code Online (Sandbox Code Playgroud)

我有这样的事情:

(defun system (cmd)
 (ext:run-program :output :stream))
Run Code Online (Sandbox Code Playgroud)

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

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

(defun system (cmd)
  (with-output-to-string (stream)
    (ext:run-program cmd :output stream)))
Run Code Online (Sandbox Code Playgroud)

然后试着跑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
Run Code Online (Sandbox Code Playgroud)

lisp clisp stream

4
推荐指数
1
解决办法
2513
查看次数

标签 统计

common-lisp ×3

sbcl ×3

lisp ×2

stream ×2

clisp ×1