I wrote this with-input-from-pipe
function for Guile. I’m not that comfortable with dynamic-wind
or set-current-input-port
, so I’d appreciate any critiques.
(use-modules (ice-9 popen)
(srfi srfi-26))
(define (with-input-from-pipe command thunk)
(let ((old (current-input-port))
(pipe (open-input-pipe command)))
(dynamic-wind
(cute set-current-input-port pipe)
thunk
(lambda ()
(set-current-input-port old)
(close-pipe pipe)))))