if(StringUtils.isBlank(execCommand)){
warn(out, "No command need execute.");
return;
}
Executor executor = new DefaultExecutor();
executor.setWorkingDirectory(site.getParentFile());
CommandLine command = CommandLine.parse(execCommand);
out.println("========================");
info(out, String.format("Execute command: %s", command.toString()));
out.println("========================");
LogOutputStream outputStream = new LogOutputStream() {
protected void processLine(String line, int level){
log.info(String.format("Command logged an out: %s", line));
out.println(line);
}
};
LogOutputStream errorStream = new LogOutputStream() {
protected void processLine(String line, int level){
log.error(String.format("Command logged an error: %s", line));
out.println(line);
}
};
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, errorStream);
executor.setStreamHandler(streamHandler);
executor.setProcessDestroyer(processDestroyer);
// (new Thread(new Runnable(){
// public void run(){
// try{
// executor.execute(command);
// }
// catch(Exception e) {
// log.warn(String.format("Command exited with error %s", e.getMessage()));
// }
// }
// })).start();
executor.execute(command);
}