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: stktrc <stktrc@yahoo.com>
Date: 07 Nov 2003 10:42:33 +0100
Sender: news <news@sea.gmane.org>
ZHAO Wei <zhaoway@public1.ptt.js.cn> writes:

> Hello!
> 
> What I want to achieve is that: two processes, one in scsh, the other
> a usual shell command, to read/write from/to each other.
> 
> I tried (|+ ((0 1) (1 0)) ...) but it gives me errors:
> 
> Error: fdes was already assigned to an inport
>         1
> 
> I also tried (run/port (shell command) (= 0 ,(current-output-port)))
> but still with no luck. There is no error message, but the output from
> the scsh process is not directed to the shell command but being
> printed in local display. (I used netcat to test.)

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

,open srfi-11

(define (fork/ports thunk)
  (let-values
   (((p-in c-out) (pipe))
    ((c-in p-out) (pipe)))
   (fork
    (lambda ()
      (move->fdes c-in 0)
      (move->fdes c-out 1)
      (thunk)))
   (values p-in p-out)))


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