chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using a pipe in chicken 5


From: Mark Fisher
Subject: Using a pipe in chicken 5
Date: Thu, 6 Aug 2020 12:01:40 +0100

Hi Chicken Users,

I'm a new user of chicken, and am using it to learn scheme.
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))))

When I run this, it throws an error:

> (open-input-file*) cannot open file - Invalid argument: 4

If I drop the (open-input-file*) to just (let ([p-out out])
the program runs, but putting any data into either end of the pipe, it
never causes the thread to continue, so I don't get any data.

I'm compiling with:
> csc example.scm

I'm sure the pipe is being created, as I can see fds under
/prod/<PID>/fd/* and am able to read / write both ends of the pipe on
the command line with:

> IN_FD="/proc/$(ps -ef | grep '[e]xample' | awk '{print $2}')/fd/3"
> OUT_FD="/proc/$(ps -ef | grep '[e]xample' | awk '{print $2}')/fd/4"
> echo "test" > $IN_FD  # I would expect this to trigger the application to 
> display the data
> cat $OUT_FD  # displays "test" in shell

and vice versa, but still my application hangs on the
(thread-wait-for-i/o!) line.

The documentation
(http://api.call-cc.org/5/doc/chicken/file/posix#sec:open-input-file.2a)
for (open-input-file*) says:

> "Opens file for the file-descriptor fileno for input or output and returns a 
> port. fileno should be a positive exact integer"

but instead, i'm getting an error that the argument is invalid.

What am I doing wrong?

Thanks.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]