How can I execute a Java application that asks for user input?


(Gunnar Hillert) #1

Hi,

How can I execute a Java application that asks for user input?

This should be fairly straightforward:

apply plugin: ‘application’

mainClassName = “a.b.c.Main”

$ gradle run

The application does start up successfully BUT it looks like any calls to inputstream.readLine(); are ignored. Is this related to:

GRADLE-1483?

Is there are work-around possible with M8?

Thanks!

Cheers,

Gunnar


Exception in thread "main" java.util.NoSuchElementException
(René Groeschke) #2

Hello Gunnar, the run task of the application plugin is of type JavaExec. As you can see in the DSL reference for the JavaExec ( http://gradle.org/docs/current/dsl/org.gradle.api.tasks.JavaExec.html ) the default input stream is set to empty. To change this behavior you can add the following to your build script:

run{
 standardInput = System.in
}

regards, René