Apologize if this trivial question has already been answered, I cannot find it at SO. Reading lines from the IDE console with this Java trivial code (Windows 7 and Eclipse Kepler):
int v;
try { while ((v = System.in.read()) != -1) System.out.println(v); }
catch (IOException e) { ; }
How the user can make the value v equal to -1? (I've tried Ctrl + d-z-x-c-s-e and other keys without repeatable behavior, but the loop is interrupted randomly)
Control
+ D
should send the EOF character as excepted , but it is an bug in Eclipse.
One of the user reported as
In Kepler 4.3 eclipse.buildId=4.3.0.M20130911-1000 on Linux the problem
still exists in the Java console. I found the following workaround:
If you leave the console to focus on another view, and then refocus on the console,
then Ctrl-D (EOF) works as expected.
Follow here
When using Eclipse in Windows, Control + Z
sends the EOF character.
Testing this out using Groovy in a Windows command prompt, ctrl-D doesn't work while ctrl-C does:
C:>groovy -e "while(v = System.in.read()){ println v }"
^D
4
13
10
-1
Terminate batch job (Y/N)? y
First I hit ctrl-D then enter, resulting in output ctrl-D, 4, 13, 10 (the last three being EOT, CR, LF, I guess, not sure what ^D amounts to in this case). Then I tried ctrl-C and the '-1' end-of-input was sent. So it seems this is dependent on the shell as Dev says.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With