2

我将如何从 Chicken Scheme 中的系统命令获取输出?

这是我通常在 NewLISP 中执行的操作:

(nth 0 (exec "<COMMAND>")) 
;; the `(nth 0...` is just there 'cause I only care about the first element in 
;; the list returned by `exec`
4

2 回答 2

2

内置于 Chicken Scheme 的 posix 单元具有 call-with-output-pipe。它可以与 utils 单元(也内置于 Chicken Scheme)中的 read-all 结合以读取 shell 命令的输出:

#;1> (use posix)
#;2> (call-with-input-pipe "echo hello world" read-all)
"hello world\n"

http://wiki.call-cc.org/man/4/Unit%20posix#call-with-output-pipe

http://wiki.call-cc.org/man/4/Unit%20utils#read-all

于 2013-11-27T05:00:58.207 回答
1

我做了一个快速的谷歌搜索,我发现了 Chicken egg, shell

这就是我最终使用鸡蛋 中的capture功能的方式。shell

(use shell)
(capture "ls -d ./")
;; -> "./\n"
于 2013-11-26T17:32:44.713 回答