开发者

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.b开发者_StackOverflow社区sh
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]);
}


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜