executeShellData(edepShellPath, businessDate);
方法一:使用Runtime.getRuntime().exec()
/**
* 方法简述:java执行shell脚本
* <p>
* 方法详细描述:使用Runtime.getRuntime().exec()
*
* @Since: 2016-04-11
* @param execPath
* @param businessDate
* @return
*/
private void executeShellData(String execPath, String businessDate) {
LOGGER.info("executeShellData贴源报表统计执行shell脚本开始!execPath[{}],businessDate[{}]",execPath, businessDate);
InputStreamReader isr = null;
String result = null;
try {
Process proc = Runtime.getRuntime().exec(
"sh " + execPath + " " + businessDate);
BufferedReader br = null;
StringBuffer sb = new StringBuffer();
try {
isr = new InputStreamReader(proc.getInputStream(),
Constant.CORE_FILE_CHARACTERSET_GBK);
br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null) {
LOGGER.info("executeShellData br.readLine()=[{}]", line);
sb.append(line).append(Constant.UNIX_LINE_FEED);
}
result = sb.toString();
} catch (Exception e) {
LOGGER.error(
"executeShellData贴源报表统计执行shell脚本获取输入流失败!result[{}]",
result, e);
} finally {
if (br != null) {
br.close();
}
if (isr != null) {
isr.close();
}
}
proc.destroy();
} catch (IOException e) {
LOGGER.error("executeShellData贴源报表统计执行shell脚本,启动进程失败!", e);
} catch (Exception e) {
LOGGER.error("executeShellData贴源报表统计,执行shell脚本失败!result[{}]",
result, e);
}
LOGGER.info(
"executeShellDataEnd贴源报表统计,java调用shell脚本结束!edepShellPath[{}], result[{}]",
execPath, result);
}