java可以通过Runtime和Process类调用外部命令
/*用这个方法会报页面超时问题*/
@RequestMapping(value="/JiaoDianData/{time}", method = RequestMethod.POST)
public @ResponseBody WrappedResult JiaoDia(@PathVariable String time){
String cmdStr = "-amend_time 2 4 -app 1200600 -date "+time;
System.out.println("重新统计" + cmdStr);
try {
Runtime.getRuntime().exec(cmdStr).waitFor();
} catch (Exception e) {
System.out.println("异常");
e.printStackTrace();
}
return WrappedResult.successWrapedResult(null);
}
使用上面这段代码 页面会报超时问题,下面这段代码解决了页面超时问题:
@RequestMapping(value="/JiaoDianData/{time}", method = RequestMethod.POST)
public @ResponseBody WrappedResult JiaoDia(@PathVariable String time){
try {
String cmdStr = " -amend_time 2 4 -app 1200600 -date "+time;
System.out.println("重新统计" + cmdStr);
Process process = Runtime.getRuntime().exec(cmdStr);
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while((line = br.readLine()) != null){
sb.append(line).append("\n");
}
String result = sb.toString();
System.out.println("start----------");
System.out.println(result);
System.out.println("over----------");
return WrappedResult.successWrapedResult("成功");
} catch (Exception e) {
System.out.println("异常");
e.printStackTrace();
return WrappedResult.failedWrappedResult("失败");
}
}