sci 2023-10-19

Is there a solid way to detect if a process has data to read on stdin in sci?

how is your question specific to SCI? SCI always runs in a host environment: JVM or JS

I see. Sorry. Do you know the answer wrt JVM? Or should I ask in #clojure?

no problem. I think java.io.InputStream has a method called .available

ok thanks 🙂

I can't figure out how to call this thing 😕

(import java.io.InputStream)
(.available InputStream)
(. InputStream available)
(. (InputStream.) available)
don't work

=> (. (FileInputStream. "/dev/stdin") available)
0
works, but seems not portable...

thanks. trying.

This seems to work for me

(.ready ^clojure.lang.LineNumberingPushbackReader *in*)

👍 1

Ah true, I guess I'm actually using that one https://docs.oracle.com/javase%2F7%2Fdocs%2Fapi%2F%2F/java/io/PushbackReader.html and not the ready of BufferedReader

I need to try it as it errors if stdin is closed (already read)

echo 42 | ys
echo 42 | ys -
I'm also allowing - to mean stdin and I check for .ready after that

@jeroenvandijk got .ready working well. Thanks again.