On Thu, Aug 06, 2020 at 12:01:40PM +0100, Mark Fisher wrote:
> Hi Chicken Users,
> 
> I'm a new user of chicken, and am using it to learn scheme.

Hello and welcome, Mark!

> I've got an issue with using pipes.
> >From various sources I've created the following example, but when run
> I get an exception.
> 
> ;; example.scm
> (import (chicken process))
> (import (chicken file posix))
> (import srfi-18)
> 
> (let-values ([(in out) (create-pipe)])
>   (print " in: " in)
>   (print "out: " out)
>   (let ([p-out (open-input-file* out)])
>     (thread-wait-for-i/o! out #:input)
>     (let ([data (read p-out)])
>       (print "data: " data))))

It looks like you swapped the meaning of in and out; you are trying to
open the "out" descriptor for reading by converting it to an input port.

Try this instead:

(import (chicken process))
(import (chicken file posix))
(import srfi-18)

(let-values ([(in out) (create-pipe)])
  (print " in: " in)
  (print "out: " out)
  (let ([p-in (open-input-file* in)])
    (thread-wait-for-i/o! in #:input)
    (let ([data (read p-in)])
      (print "data: " data))))


Cheers,
Peter

Attachment: signature.asc
Description: PGP signature

Reply via email to