CLISP:从shell命令返回stdout,stderr和retcode

时间:2015-10-13 22:24:54

标签: shell lisp common-lisp clisp

我使用Common Lisp进行某些脚本编写,并希望run-program执行shell命令。我一直在尝试操作输出以获取Ambiguous occurrence `String' It could refer to either `Main.String', defined at Testing.hs:19:1 or `Prelude.String', imported from `Prelude' at Testing.hs:16:1-14 (and originally defined in `GHC.Base') 形式的列表,但我只能从 run-program 获得输出或返回码。

这里的参数只给你(output error returncode)(没有:output):

有没有办法让这三个人?像这样:

:error

1 个答案:

答案 0 :(得分:3)

run-program返回multiple values。 您可以按照链接问题中的说明处理它们。

您链接的文档说:

  

如果:STREAM指定为:INPUT或:OUTPUT,则返回Lisp STREAM。如果:为两者指定了STREAM:INPUT和:OUTPUT,则返回三个Lisp STREAM,对于函数EXT:MAKE-PIPE-IO-STREAM。

因此你需要的是

(EXT:MAKE-PIPE-IO-STREAM "ls")

(ext:run-program "ls" :input :stream :output :stream)

然后,您必须从返回的流中读取以获取命令输出。但是,在这种情况下,您将丢失退出代码。