开发者

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

开发者 https://www.devze.com 2023-03-30 18:07 出处:网络
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?

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

精彩评论

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

关注公众号