'gets' not reading from provided reader? (JSR223+Jruby)

The following program almost works: I’m trying to read from a text file,
rather than stdin, but ‘gets’ seems to insist I type at ‘stdin’…

Is this likely a problem in JRuby, The JRuby Engine or something wrong
with the ‘javax.script’ stuff? Anybody seen this issue (or is this
correct behaviour?)

Cheers

John

package test;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import javax.script.*;

public class TestClass {

public static void main(String[] args) throws Exception {

ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine rubyEngine = factory.getEngineByName(“jruby”);
ScriptContext context = rubyEngine.getContext();

FileWriter out=new FileWriter(“C:\RUBY.OUT”);
InputStreamReader in=new InputStreamReader(new
FileInputStream(“C:\IN.TXT”));
context.setWriter(out);
context.setReader(in);

rubyEngine.eval(“a=gets;puts a”);
out.flush();
out.close();
in.close();
}
}

Further information:

Even doing this:

//
FileInputStream fis=new FileInputStream(“in.txt”);
System.setIn ( fis );
//

Results in ‘gets’ trying to get input from the existing standard in it
seems…
I’m running this from a Netbeans IDE…I wonder if that is highjacking
the in/out streams …will check running standalone…

I’m running this from a Netbeans IDE…I wonder if that is highjacking
the in/out streams …will check running standalone…

Nope…same thing…but I can kinda force it to work (this is no good to
me in general as it happens) with:

java -jar < in.txt

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs