当前位置: 动力学知识库 > 问答 > 编程问答 >

java - 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'

}

网友答案:

It's working fine on my windows 7 machine with IntelliJ IDEA 14 community edition.

网友答案:

It is a known bug in Intellij Idea: bug description

分享给朋友:
您可能感兴趣的文章:
随机阅读: