[racket] Embedding multiline shell scipts
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
planet:
;http://planet.plt-scheme.org/package-source/ryanc/scripting.plt/1/1/misc.ss
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)])
out))
;;multiline script format example
(system/output "
cd ~/
expect {
{}
{}
{}}
ls
")
;>> 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
format
I still hate command line scripting, but atleast I can do it from Racket!
br, jukka