问题的提出:
- shell脚本要做离线的数据处理任务
- java调用脚本,将这种处理任务封装成webservice
特点:
- shell处理单个时间长
- 每次要处理文件量大
这里目前只做调用分析:
原来的:
private void runShell(String cmd){ try{ logger.info("the command "+cmd); // create a process for the shell ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd); pb.redirectErrorStream(true); // use this to capture messages sent to stderr Process shell = pb.start(); InputStream shellIn = shell.getInputStream(); // this captures the output from the command int shellExitStatus = 0; try { shellExitStatus = shell.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } // wait for the shell to finish and get the return code // // at this point you can process the output issued by the command // // for instance, this reads the output and writes it to System.out: int c; while ((c = shellIn.read()) != -1) { logger.info("shell read value:"+c); } // close the stream shellIn.close(); logger.info(" *** End *** "+shellExitStatus); logger.info("pb command "+pb.command()); logger.info("pb command dir "+pb.directory()); logger.info(pb.environment()); logger.info(System.getenv()); logger.info(System.getProperties()); } catch (IOException ignoreMe) { ignoreMe.printStackTrace(); } }