2015년 4월 30일 목요일

web 에서 shell 실행


/**
 * shell 실행
 * @return 목록
 */
private void getRcvList() {

//shell 실행 (rcvlist.txt 를 생성한다)
List<String> cmd     = new ArrayList<String>();
ProcessBuilder bld   = null;
Process process      = null;

try {
cmd.add("sample.sh"); //실행 shell
   cmd.add("param1"); //
   cmd.add("param2")); //
   bld = new ProcessBuilder(cmd);
   process = bld.start();
   process.waitFor();

} catch (Exception e) {
e.printStackTrace();

//실패기록
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
......
} finally {
try {
if (process.getErrorStream() != null) process.getErrorStream().close();
if (process.getInputStream() != null) process.getInputStream().close();
if (process.getOutputStream() != null) process.getOutputStream().close();
} catch (IOException ex) {
ex.printStackTrace();
}
}

}

댓글 없음:

댓글 쓰기