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();
}
}