[racket] Embedding multiline shell scipts
Hi,
having tested the program a bit further I noticed that it still behaves
differently than intended in two ways
1) Preferably the inputs could take the same format as if in separate files,
for example
(define script1
"
#!/usr/bin/expect
command 1
command 2
command 3
")
(define script2
"
#!/bin/sh
command 1
command 2
command 3
")
That is, the first line could point to a different program, but also to keep
the overall format close to the original script file.
2) eventhough the commands 1,2 and 3 could interact with each other, only
the last command should return its output (or whatever the script would
return if run from the file).
Sorry, I didn't explained it well.
br, jukka
> -----Original Message-----
> From: users-bounces at racket-lang.org
> [mailto:users-bounces at racket-lang.org]On Behalf Of Manfred Lotz
> Sent: 06 February 2011 22:50
> To: users at racket-lang.org
> Subject: Re: [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
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users