[racket] Embedding multiline shell scipts

From: Jukka Tuominen (jukka.tuominen at finndesign.fi)
Date: Tue Feb 8 06:32:15 EST 2011

Hi all,

I think I found a(nother) solution to the problem having googled and tested
some more.

The system/output procedure I've been referring to wasn't an inbuilt
procedure as I remembered having used it so much. You can find it from


and you can use it as follows:

(require racket)

(define (system/output command)
  (define (system/exit-code+output command)
    (let* ([out (open-output-string)]
           [control (process/ports out #f #f command)]
           [p (list-ref control 4)])
      (p 'wait)
      (values (p 'exit-code)
              (get-output-string out))))
  (let-values ([(e out) (system/exit-code+output command)])

;;multiline script format example

(system/output "
cd ~/
expect {

;>> lists home directory folders and files

A few remarks
- You can move forward step by step as in command line (e.g. cd changes the
pwd for the next command)
- It accumulates output rather than returning just the last one (e.g. ls ls
would double the output)
  (you can propably tweak system/output definition if needed/wanted)
- Output format is a string
- You can also include multiline expect script using its { {} {} {} } arg

I still hate command line scripting, but atleast I can do it from Racket!

br, jukka

Posted on the users mailing list.