scheme shell
about
download
support
resources
docu
links
 
scsh.net

Run Strings Status

run/strings-status

run/strings returns a process' output as a list of strings, thus, is a very useful procedure. However, if the called process fails, run/strings only returns '() and you don't get the process exit code. Here is a macro that gives you both. An example:

  > (run/strings-status (cat /etc/hots))
  cat: /etc/hots: No such file or directory
  ; 2 values
  '()
  256

Here's the macro:

  (define-syntax run/strings-status
    (syntax-rules ()
       ((_ epf ...)
        (call-with-values
           (lambda ()
               (run/port+proc epf ...))
           (lambda (port proc)
              (let* ((string-list (port->string-list port))
                     (status (wait proc)))
                 (close-input-port port)
                 (values string-list status)))))))

See also RunStatusStreams.

-Eric


RunStringsStatus - raw wiki source | code snippets archive