scheme shell
about
download
support
resources
docu
links
 
scsh.net
From: Eric Marsden <emarsden at laas fr>
Subject: Re: two process read/write from/to each other
Date: Thu, 13 Nov 2003 17:45:34 +0100
Message-ID: <wzibrrgusi9.fsf at melbourne laas fr>

>>>>> "sk" == stktrc  <stktrc at yahoo com> writes:

  sk> The following procedure forks a child and returns ports on the childs
  sk> stdin and stdout.  It would be interesting to hear if there are other,
  sk> perhaps more standard, solutions to this.

I have used the following code in the past, which is an analogue of
the "open2" function in Perl.

(define (open2 cmd)
  (receive (child-read parent-write) (pipe)
  (receive (parent-read child-write) (pipe)
    (cond ((fork)                       ; parent process
           (close child-read)
           (close child-write))
          (else                         ; child process
           (close parent-read)
           (close parent-write)
           (move->fdes child-read 0)
           (move->fdes child-write 1)
           (call-terminally
            (lambda () (run ,((infix-splitter " ") cmd))))))
    (values parent-read parent-write))))

--
Eric Marsden                          <URL:http://www.laas.fr/~emarsden/>

Up