scsh-users
[Top] [All Lists]

Re: two process read/write from/to each other

To: scsh@zurich.csail.mit.edu
Subject: Re: two process read/write from/to each other
From: Eric Marsden <emarsden@laas.fr>
Date: Thu, 13 Nov 2003 17:45:34 +0100
Organization: LAAS-CNRS http://www.laas.fr/
Sender: news <news@sea.gmane.org>
>>>>> "sk" == stktrc  <stktrc@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/>


<Prev in Thread] Current Thread [Next in Thread>