The function system/output below uses the process function in MzLib?'s process.ss to capture the output of the program.
(require (lib"process.ss"))
;; system/output : string -> (U string #f)
;;
;; Synchronously run the given command through the shell and
;; capture standard output.
;;
;; Returns the standard output or #f if the command failed
;;
;; If the command blocks for any reason (e.g. waiting for
;; input) this function will as well.
(define (system/outputcommand-string)
(let ([p (open-output-string)])
(parameterize ([current-output-portp])
(if (systemcommand-string)
(get-output-stringp)
#f))))
system/output runs its command via the shell, so programs are resolved using the PATH, and shell functions such as wildcards can be used in commands.
Note there was a subtle bug in the previous version of system/output, which built on the process function (which in turn builds on the built-in subprocess function). The ports returned by process have a limited buffer for output, and once that buffer is full execution will halt. This leads to strange behaviour -- processes that produce small output will succeed, but when the output gets larger they will suddenly hang. It is much simpler to build on system which takes care of asynchronously copying the output to the current-output-port.