This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
running programs.
- To: guile at sourceware dot cygnus dot com
- Subject: running programs.
- From: Clark McGrew <mcgrew at ale dot physics dot sunysb dot edu>
- Date: Thu, 11 Nov 1999 08:17:17 +0900 (JST)
- Reply-to: clark dot mcgrew at sunysb dot edu
Hi Everybody,
This is sort of a question/proposal/advertisement.
I like using guile to write scripts whenever possible, since I find it
a lot easier to use than some of the other options. Unfortunately,
I've run into the same snag several times; I don't know of any easy
way to feed data to an external program and then collect it's output.
Is there a simple way to do what I'd like?
I think this can be done with scsh, but it's a big package. I also
don't particularly like scsh since it seems like a bad compromise
between shell and scheme.
My proposed solution is "(run exec-file [argument ...] [input-port])"
where exec-file and argument(s) are strings that will be used to build
a process. It would be used like this:
(with-input-from-port
(run "grep" "hello"
(run "sed" "s/goodbye/hello"
(open-input-port "big-file")))
(lambda ()
;; do something with the output of grep))
(define from-myprog #f)
(define to-myprog
(let ((p (pipe)))
(set! from-myprog
(run "myprog"
(run "grep" "hello" (car p))))
(close-port (car p))
(cdr p)))
(format to-myprog "hello my-prog)
(close-port to-myprog)
The advertisement is that I've already coded something that "almost"
does this. I've included several keyword arguments to handle stuff
like redirection, dumping the output to /dev/null, and imposing time
limits on the child process. The code has some *major* bugs
(especially in the redirection sections), but it handles the simple
cases I showed above. If there isn't a better solution; I'd be happy
to post it. If there is a better solution; I'd be happy to use it.
Cheers,
Clark