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 と組み合わせて、シェル コマンドからの出力を読み取ることができます。
#;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
簡単なグーグル検索を行ったところ、チキンの卵、殻に出くわしました。
これが、卵 のcapture
関数を使用することになった方法です。shell
(use shell)
(capture "ls -d ./")
;; -> "./\n"