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

StackOverflow https://stackoverflow.com/questions/7201424

  •  13-01-2021
  •  | 
  •  

سؤال

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]);
}
هل كانت مفيدة؟

المحلول

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");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top