Question

How would I go about getting the output from a system command in Chicken Scheme?

Here's how I do I typically do it in 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`
Was it helpful?

Solution

The posix unit, built in to Chicken Scheme, has call-with-output-pipe. It can be combined with read-all from the utils unit (also built-in to Chicken Scheme) to read the output from a shell command:

#;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

OTHER TIPS

I did a quick google search and I came across the Chicken egg, shell.

Here's how I ended up using the capture function from the shell egg.

(use shell)
(capture "ls -d ./")
;; -> "./\n"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top