import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* Created by debuggerx on 17-2-14.
*/
public class ImageLocalizationUtil {
public static String ImageLocalization(String uploadpath , String content) {
String res = "";
try {
String[] cmd = {"python", uploadpath + "/
ImageLocalization.py" ,uploadpath + "/xiumi/", content};
Process process = Runtime.getRuntime().exec(cmd);
String line = null;
InputStream is = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
while ((line = reader.readLine()) != null) {
System.out.println(line);
res += line;
}
//process.waitFor();
is.close();
reader.close();
process.destroy();
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
}
我这个因为就在一台服务器上跑的,所以 java 调用 python 并阻塞就拉倒了。。
或者直接用 linux 的 pipe 管道做通讯,直接重定向输入输出就很随意了。
不同机器上最简单的就是 python 执行结束后 urllib 调一下 java 写的 web 接口了事