User Input ignored in JShell console

Answered

(IntelliJ IDEA 2019.3.3 (Ultimate Edition) Build #IU-193.6494.35)

The JShell console doesn't feel the need to wait for user input as it does when run 'manually' via a main method.
import java.util.Scanner;
Scanner scanner = new Scanner(System.in);
System.out.println(scanner.nextLine());

Gives output in console:

Defined import java.util.Scanner

Defined field Scanner scanner = java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\QNaN\E][infinity string=\Q∞\E]

No line found
System.out.println(scanner.nextLine())

0
3 comments

Hello,

Does it work fine in jshell outside IDE? Also please check this thread for. possible solutions: https://stackoverflow.com/questions/48063408/how-to-take-user-input-in-jshell-script

1

It fails in exactly the same way unless I set --exectution local (help from: https://stackoverflow.com/a/59476159/5353824).

As is (same as Intelij JShell console) :

C:\Program Files\Java\jdk-10.0.2\bin>jshell "%userprofile%/jshell_console.snippet"
java.util.NoSuchElementException thrown: No line found
at Scanner.nextLine (Scanner.java:1651)
at (#3:1)

With setting:

C:\Program Files\Java\jdk-10.0.2\bin>jshell --execution local "%userprofile%/jshell_console.snippet"
TEXT TO ECHO
TEXT TO ECHO

So is there anyway to set this JSHELL config property for/in the Intelij JShell console?

0

Currently it's not possible. Please vote for the related request on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-179252

0

Please sign in to leave a comment.