This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
popen behavior - interactive processes
- To: guile at sourceware dot cygnus dot com
- Subject: popen behavior - interactive processes
- From: Allister MacLeod <listopad at mv3d dot com>
- Date: Tue, 21 Mar 2000 18:57:02 -0500
How come (ice-9 popen) only does one-way pipes? I'm interested in
using the guile interpreter as a replacement for expect/Tcl, so I'd
like to be able to set up a background process with ports for both
input and output (or possibly a bidirectional port, if such a thing
exists)
So, I've been able to get close to what I want by looking at popen.scm
and modifying it a little.. something like
(define (open-two-way)
(define (pipe-nobuf) (let ((p (pipe))) (setvbuf (cdr p) _IONBF) p))
(define (shutoff in out) (map close-port (list (cdr in) (car out))))
(let ((c2p (pipe-nobuf)) (p2c (pipe-nobuf)))
(let ((pid (primitive-fork)))
(cond ((= pid 0)
(set-batch-mode?! #t) ;blindly copied from popen.scm
(shutoff p2c c2p)
(let loop ((x (read-char (car p2c))))
(write-char (if (char=? x #\space) #\. x) (cdr c2p))
(loop (read-char (car p2c)))))
(else
(shutoff c2p p2c)
(cons (cons (car c2p) (cdr p2c)) pid))))))
This works just fine.. I can feed in characters and they come out the
same except for spaces which turn into dots. What I can't figure out
how to do is make the same thing work with a couple of move->fdes
calls and an execle instead of the loop (which, btw, is there a better
way to write that kind of loop whose argument is always the same
expression?)
I just keep ending up with zombies to feed to waitpid. Maybe I'm
misunderstanding the way move->fdes works, but when I replace the loop
with :
(move->fdes (car p2c) 0)
(move->fdes (cdr c2p) 1)
(apply execlp "/bin/sh" "/bin/sh" ())
sh seems to die before writing any characters to the port. On the
other hand, when I substitute /bin/date for /bin/sh, I'm able to pull
characters from it.
I guess the real question is, am I even looking in the right place?
Is it conceivable that an interactive process can be spawned this way?
If not, is there some other way that's better?