hi forum members,
I try to call a ruby script twice from a java program, with different
arguments. It seems I cannot set the argv twice; only the first call to
setArgv actually has effect.
There must be someting I have misunderstood. I hope you can help me out
of this.
The following minimal script shows my problem. It outputs
test.rb
string1
test.rbstring1
The jruby script (test.rb) is
argument = (ARGV.length > 0 ? ARGV[0] : ‘default’)
puts ‘test.rb’
puts( " >> #{argument}")
and the java code (Tester.java) is
import org.jruby.embed.ScriptingContainer;
import org.jruby.embed.PathType;
public class Tester
{
Tester (String jrubyhome, String filename, String [] argv)
{
ScriptingContainer container = new ScriptingContainer();
container.setArgv (argv);
container.runScriptlet(PathType.ABSOLUTE, jrubyhome + ‘/’ +
filename);
}
public static void main(String[] args)
{
new Tester ("/export/home/rudd/jruby", "test.rb",
new String[] { "string1", "string2" });
new Tester ("/export/home/rudd/jruby", "test.rb",
new String[] { "blop", "blop2" });
}
}
I have run this using the jruby 1.5.1.1.jar and the latest
jruby-complete-1.7.3.jar.
As you can see, the second call to ScriptingContainer.setArgv does
nothing. Who can explain to me what I can do be able to run the
script with different argument vectors?
thanks in advance, Rudd