-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJyScriptRunner.java
More file actions
52 lines (35 loc) · 1.13 KB
/
JyScriptRunner.java
File metadata and controls
52 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package jython;
import java.util.Properties;
import org.python.util.PythonInterpreter;
import org.python.core.PySystemState;
/**
* Runs Jython scripts.
*/
public class JyScriptRunner {
private PythonInterpreter interp;
/**
* Initializes the Jython interpreter.
*/
public void initialize(String pythonHome) {
Properties props = new Properties();
props.put("python.home", pythonHome);
PythonInterpreter.initialize(
System.getProperties(),
props,
new String[0]);
interp = new PythonInterpreter(null, new PySystemState());
}
/**
* Runs the given script.
*/
public void run(String fileName) {
interp.execfile(fileName);
}
public static void main(String[] args) {
String fileName = args[0];
JyScriptRunner runner = new JyScriptRunner();
String pythonHome = System.getProperty("python.home");
runner.initialize(pythonHome);
runner.run(fileName);
}
}