Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JLine 2.11 ignores input redirection on Windows 7 #103

Open
inkytonik opened this issue Aug 5, 2013 · 1 comment
Open

JLine 2.11 ignores input redirection on Windows 7 #103

inkytonik opened this issue Aug 5, 2013 · 1 comment

Comments

@inkytonik
Copy link

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
Copy link
Author

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

  • By default, the {@link #wrapInIfNeeded(java.io.InputStream)} method will attempt
  • to test to see if the specified {@link InputStream} is {@link System#in} or a wrapper
  • around {@link FileDescriptor#in}, and if so, will bypass the character reading to
  • directly invoke the readc() method in the JNI library. This is so the class
  • can read special keys (like arrow keys) which are otherwise inaccessible via
  • the {@link System#in} stream. Using JNI reading can be bypassed by setting
  • the jline.WindowsTerminal.directConsole system property
  • to false.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant