This question explains how to use System.in
when running a task to run a specific class in a project.
But for me currently it's not working: although I have included the application
plugin and the following lines in build.gradle
:
mainClassName = "misc.StreamsExp"
run{
standardInput = System.in
}
task stream( type: JavaExec, dependsOn: assemble ){
classpath sourceSets.main.runtimeClasspath
main = "misc.StreamsExp"
}
the line with readLine
in the app code below should be blocking but it's not:
BufferedReader br = new BufferedReader(new InputStreamReader( System.in ));
String enteredLine = "";
while( enteredLine == null || ! enteredLine.equals( "q" )){
System.out.println( "spuds");
enteredLine = br.readLine();
}
... instead the thing just spins on forever:
spuds
spuds
spuds
...
NB I am on a Windows 10 OS, with Java 8.91. I have tried both the Windows DOS console and Cygwin.
NB2 The same thing occurs when I run this stream
task inside Eclipse (Gradle STS Eclipse plugin)... but not when I do Run as --> Java application
: then the blocking occurs as expected.