我将如何从 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`
我将如何从 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`
内置于 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
我做了一个快速的谷歌搜索,我发现了 Chicken egg, shell。
这就是我最终使用鸡蛋 中的capture
功能的方式。shell
(use shell)
(capture "ls -d ./")
;; -> "./\n"