使用javax.script.ScriptEngineManager object.Put方法将参数从Java代码传递到Python模块变得越来越困难,但是由于该参数返回null,因此无法在python中使用参数;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.StringReader;
import java.io.StringWriter;
import java.lang.*;
import javax.script.ScriptContext;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleScriptContext;
import javax.script.SimpleScriptContext;
import javax.script.ScriptEngine;
public class CallPythonScript {
public static void main(String[] args) {
// TODO Auto-generated method stub
StringWriter writer=new StringWriter();
StringReader s=new StringReader("3");
ScriptEngineManager manager1=new ScriptEngineManager();
ScriptContext context=new SimpleScriptContext();
context.setWriter(writer);
ScriptEngine engine=manager1.getEngineByName("python");
//Trying to fetch value return to Engine argument into my python code
engine.put(engine.ARGV, "12");
try
{
engine.eval(new FileReader("printprogram.py"),context);
System.out.println("helloexception");
我无法通过使用sys.argv在python代码中使用参数值在python中返回空值。有人可以调查我的问题 在此先感谢