It was like one of those Aha! moments when I finally found how to invoke one script from within another. It is so simple!!
Say you have a script RunScript.groovy which is as follows:
package com.singhanuvrat.sandbox
println "Whoa!! ${input}"
Now you want this RunScript.groovy to be called from CallerScript.groovy with different values for the variable input. Our script will be:
package com.singhanuvrat.sandbox
GroovyScriptEngine gse = new GroovyScriptEngine("src/com/singhanuvrat/sandbox");
Binding binding = new Binding();
binding.setVariable("input", "world");
gse.run("RunScript.groovy", binding);
Infact, using the binding, we can also extract value of variables from the called script. Now we shall have fun!
Popularity: 3% [?]
Related posts:
