I am working with beanshell bsh-2.0b4.jar file. I have build path and used it in a java program. I have managed to get the get the print statements from the console. But if a value is being returned, how to get the return value.
import java.io.*;
import bsh.Interpreter;
import bsh.EvalError;
public class CaptureDis {
/**
* @param args
*/
public static void main(String[] args) {
Interpreter i = new Interpreter();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps2 = System.out;
try {
//i.eval(System.out.println("System.out.println(\"test\");"));
i.eval("int x=2; int y=3; int res=x+y; return res");
i.getOut();
} catch (EvalError e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String out = baos.toString();
System.setOut(ps2);
System.out.println(out);
}
}