2

I am trying to figure out how to pass arguments to a second script that I call from an initial script. The Beanshell documentation says nothing about this. Does anyone know how to do this?

// Start.bsh
import bsh.Interpreter;
Interpreter i = new Interpreter();
i.source("Target.bsh");

.

// Target.bsh
System.out.println("No. of arguments are: " + args.length);
for(int i= 0;i < args.length;i++) {
  System.out.println("Argument " + i + " is : " + args[i]);
}
djangofan
  • 28,471
  • 61
  • 196
  • 289

1 Answers1

5

AFAIK, you can't pass command line parameters through i.source("file.bsh"). You'll need to do something like this:

Interpreter i = new Interpreter();
NameSpace ns = i.getNameSpace();
ns.setVariable("args", new String[]{"param1", "param2"}, false);
i.source("Target.bsh");
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288