jline / jline2

Jline 2.x
http://jline.github.com/jline2/
Other
712 stars 183 forks source link

JLine 2.11 ignores input redirection on Windows 7 #103

Open inkytonik opened 11 years ago

inkytonik commented 11 years ago

I've run into an issue when using the Scala REPL with standard input redirection on Windows 7. This is a blocker for my Sublime Text 3 Scala Worksheet plugin which relies on input redirection to run the REPL.

After some experimentation it seems that the issue is due to the way that JLine behaves. In more detail and removing the Scala complication, I compiled and ran the example from here:

https://github.com/jline/jline2/blob/master/src/test/java/jline/example/Example.java

as

java -cp .:jline-2.11.jar jline.example.Example none <input 

where input contains

foo 
bar 

On Windows 7 the prompt appears but the program apparently sees none of the input from the file, so it just sits there waiting for interactive input.

On Mac OS X the input is passed through to the program as expected and the program exits when the end of file is reached.

Opening the terminal using

ConsoleReader console = new ConsoleReader(System.in, System.out, new TerminalSupport(true) {}); 

makes it work, but this doesn't seem like a desirable general approach.

inkytonik commented 11 years ago

Some code reading revealed a partial work-around for this problem. WindowsTerminal.java says:

It appears that using JNI reading causes the stdin redirection not to work. Setting that property to false makes it work again. For my use case this is a reasonable workaround, since I am running the JLine-using program in a non-interactive setting where things like arrow keys can't be used.