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)))
      (cute set-current-input-port pipe)
      (lambda ()
        (set-current-input-port old)
        (close-pipe pipe)))))


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.