I am using below code to execute a python script from within a Java class:
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.SimpleScriptContext;
StringWriter writer = new StringWriter();
ScriptEngineManager manager = new ScriptEngineManager();
ScriptContext context = new SimpleScriptContext();
context.setWriter(writer);
ScriptEngine engine = manager.getEngineByName("python");
engine.eval(new FileReader("test.py"), context);
I want to know how can I call a function inside test.py with above method and also pass some parameters to that function?
Note: I know a better way to execute the python script is through using Process but due to system requirements I do not want to use Process approach as it spawns a new process with each execution.