[racket] Embedding multiline shell scipts

From: Jukka Tuominen (jukka.tuominen at finndesign.fi)
Date: Sun Feb 6 16:16:04 EST 2011

Great, thanks Thomas!

br, jukka

> -----Original Message-----
> From: thomas.chust at googlemail.com [mailto:thomas.chust at googlemail.com]On
> Behalf Of Thomas Chust
> Sent: 06 February 2011 22:37
> To: Jukka Tuominen
> Cc: users at racket-lang.org
> Subject: Re: [racket] Embedding multiline shell scipts
> 
> 
> 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
> 
> 
> -- 
> When C++ is your hammer, every problem looks like your thumb.


Posted on the users mailing list.