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...Maybe you can use . That's what I did here: https://github.com/jeroenvandijk/edntail/blob/bff45967f6837ef863d53af395512408877e362e/src/jeroenvandijk/edntail/api.clj#L56
thanks. trying.
This seems to work for me
(.ready ^clojure.lang.LineNumberingPushbackReader *in*)
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.