static void runpython() throws IOException, InterruptedException {
String[] args = new String[] {"youpath2python\\python.exe","youscriptpath\\test.py","a","b", "c","d" };
Process process = Runtime.getRuntime().exec(args);
InputStream inputStream = process.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line;
try {
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
# python脚本test.py
import sys
print "script name:", sys.argv[0]
for i in range(1, len(sys.argv)):
print "Parameter:", i, sys.argv[i]
网友评论