public String execPHP(String scriptName, String param) {
StringBuilder output = new StringBuilder();
BufferedReader input = null;
String phpPath = "D:/xampp/php/php.exe";
try {
String line;
Process p = Runtime.getRuntime().exec(phpPath + " " +scriptName + " " + param);
input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
output.append(line);
// p.destroy();//根据系统不同可能需要
}
p.destroy();
} catch (Exception err) {
err.printStackTrace();
}finally{
if(input != null){
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return output.toString();
}
//调用php算法
conclusion = runPHP.execPHP(ALGORITHM_RESIDUES_URL,imageResiduesId);
//php接收
$id = $argv[1];
因为此方法是java开进程直接调用php,因此是以内存方式传参