[racket] Embedding multiline shell scipts
On Sun, 6 Feb 2011 21:37:12 +0100
Thomas Chust <chust at web.de> wrote:
> 2011/2/6 Jukka Tuominen
> <jukka.tuominen at finndesign.fi>:
> > [...]
> > I slightly modified the Manfred's code to capture the output
> > [...]
>
> Hello,
>
> the code seems somewhat more complicated than necessary to me and it
> lacks some cleanup and error handling. I would suggest to use the
> available utilities from racket/port to simplify the I/O code and the
> control procedure returned from process to at least wait for the
> external process to finish.
>
> A module like this should do the trick:
>
> #lang racket/base
> (require
> racket/match
> racket/port
> racket/system)
>
> (define (shell command)
> (match-let* ([(list stdout stdin pid stderr control) (process
> command)] [lines (port->lines (merge-input stdout stderr))])
> (close-output-port stdin)
> (close-input-port stdout)
> (close-input-port stderr)
> (control 'wait)
> (case (control 'status)
> [(done-ok)
> lines]
> [(done-error)
> (error
> 'shell "~e failed with exit code ~a"
> command (control 'exit-code))])))
>
> (provide
> (all-defined-out))
>
> Ciao,
> Thomas
>
>
Thomas,
Thanks for improving my code. I'm still a racket beginner.
--
Manfred