This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

running programs.


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]