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]
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者