需要用到需要用到jython.jar
java example:
public static void main(String[] args) {
//定义参数
String[] args2 = {"arg1","arg2"};
//设置参数
PythonInterpreter.initialize(null, null, args2);
PythonInterpreter interpreter = new PythonInterpreter();
//执行
interpreter.execfile("E:\\jython.py");
System.out.println("----------run over!----------");
}
python的程序:
#!/bin/env python
import time
import sys
argCount = len(sys.argv)
print('before sleep')
time.sleep(5);
print('after sleep')
for str in sys.argv:
print(str)