最近写jython脚本,想获得一个python脚本执行的结果。如果一个函数需要传入环境变量参数,需要注意。
# -*- coding: utf-8 -*-
from java.lang import Runtime
from java.io import *
cmd = "C://Python27//python.exe E:\\Temp\\mypython.py"
p = Runtime.getRuntime().exec(cmd, ["PYTHONPATH=C://Python27"], File("E:\\Temp\\"));
p.waitFor()
p.exitValue()
objIS = p.getInputStream()
isr = InputStreamReader(objIS)
objBR = BufferedReader(isr)
while True:
strLine = objBR.readLine()
if strLine != None:
print strLine
else:
break