I have created a simple console application for java with an JavaBufferedReader to read the commands from the terminal. For some reason the first command issued is always completly ignored. Even while debugging no value gets read and the input String is still not initialized. After issueing a second command the input String gets the value I wrote in the console.
I am using IntelliJ and the integrated terminal with gradle and JDK 11.
I litterly can't see any reason, why the first command is just completly ignored.
BufferedReader inReader = new BufferedReader(new InputStreamReader(System.in));
And the main shell functionality
public void runMainLoop() throws IOException {
boolean quit = false;
while (!quit) {
System.out.print("prompt> ");
final String input = inReader.readLine(); // <-- This input gets no value after pressing "enter".
if (input == null) { // all other "enter" after the first one are working
break;
}
try (final Scanner scanner = new Scanner(input)) {
scanner.useDelimiter("\s+");
if (!scanner.hasNext()) {
printError("No command specified!");
break;
}
switch (scanner.next().toLowerCase()) {
case "help":
printHelpMessage();
break;
case "quit":
quit = true;
println("Terminate...");
break;
default:
printError("Unknown command given.");
printHelpMessage();
break;
}
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…