djangofan
djangofan

Reputation: 29689

Can I pass arguments to a external Beanshell script, sourced from another Beanshell script?

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

Upvotes: 2

Views: 1434

Answers (1)

Bart Kiers
Bart Kiers

Reputation: 170298

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");

Upvotes: 5

Related Questions