I am executing groovy script in java:
final GroovyClassLoader classLoader = new GroovyClassLoader();
Class groovy = classLoader.parseClass(new File("script.groovy"));
GroovyObject groovyObj = (GroovyObject) groovy.newInstance();
groovyObj.invokeMethod("main", null);
this main method println some information which I want to save in some variable. How can I do it ?
You would have to redirect System.out into something else..
Of course, if this is multi-threaded, you’re going to hit issues
It’s probably better (if you can) to write our scripts so they return something rather than dump to system.out