rlwhitcomb / utilities

Some of my personal utility programs
MIT License
2 stars 0 forks source link

Deal with "read('@')" EOF error #450

Open rlwhitcomb opened 2 years ago

rlwhitcomb commented 2 years ago

Trying to read from the console, where you need an EOF (Ctrl-Z or Ctrl-D) to end the input, then gives an EOF exception trying to read the Console again:

a=read('@') this is a test ^Z a = read ('@') -> "this is a test\r\n" Exception in thread "main" java.io.IOError: java.io.IOException: Stream Closed at java.base/java.io.Console.readLine(Console.java:259) at info.rlwhitcomb.calc.Calc.main(Unknown Source) Caused by: java.io.IOException: Stream Closed at java.base/java.io.FileInputStream.readBytes(Native Method) at java.base/java.io.FileInputStream.read(FileInputStream.java:276) at java.base/sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:270) at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:313) at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:188) at java.base/java.io.Console$LineReader.read(Console.java:495) at java.base/java.io.Console.readline(Console.java:434) at java.base/java.io.Console.readLine(Console.java:255) ... 1 more

rlwhitcomb commented 2 years ago

One solution would be to use a special method to read from the console in REPL mode and terminate at a blank line, or something other than the Ctrl-Z/Ctrl-D EOF char.

rlwhitcomb commented 2 years ago

There is the SysConsole class which should be the place to implement this special reader.