Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for user input while debugging on IntelliJ IDEA and Gradle

I have the simplest Java application that just works if executed from command line. But if I want to debug it through IntelliJ IDEA 14 Ultimate, the System.in.read() part always returns -1, without ever typing anything into it:

import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        System.out.println("This is a test... Hit [enter] to exit.");
        int cha = System.in.read();
        System.out.println("You hit [enter], exiting...");
    }
}

Is this some kind of issue with Windows 8.1 or is it IntelliJ IDEA related?

UPDATE: I have found out the issue presents itself only when starting the application through Gradle (gradlew run), so it's a Gradle issue. This is my build.gradle:

apply plugin: 'java'
apply plugin: 'application'

sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '1.0'
mainClassName = 'net.frakbot.ws.Main'

repositories {
    mavenCentral()
}

run {
    main = 'net.frakbot.ws.Main'
    standardInput = System.in
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}
like image 766
frapontillo Avatar asked Oct 19 '22 21:10

frapontillo


1 Answers

It is has been a known bug in Intellij Idea: bug description

EDIT: Apparently, as pointed out in the comments, it has been fixed since this answer was given and patched Intellij will be released in Summer 2017.

like image 151
lukeg Avatar answered Oct 28 '22 19:10

lukeg