List of usage examples for org.apache.commons.exec PumpStreamHandler setStopTimeout
public void setStopTimeout(final long timeout)
From source file:com.nts.alphamale.shell.AdbShellExecutor.java
/** * @param cmd adb /*ww w . j a va 2 s . co m*/ * @param synch ? ? true: synchronous, false: asynchronous * @param (ms) * @return Executor Standard Output? Map */ public Map<String, Object> execute(CommandLine cmd, boolean synch, long timeoutMilliseconds) { Map<String, Object> executorMap = new HashMap<String, Object>(); DefaultExecutor executor = new DefaultExecutor(); PipedOutputStream pos = new PipedOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(pos, System.err); streamHandler.setStopTimeout(timeoutMilliseconds); DataInputStream dis = null; try { dis = new DataInputStream(new PipedInputStream(pos)); } catch (IOException e) { //log.error(e.getCause() + " : " + e.getMessage()); } executor.setStreamHandler(streamHandler); ExecuteWatchdog watchDog = new ExecuteWatchdog(timeoutMilliseconds); executor.setWatchdog(watchDog); try { if (synch) executor.execute(cmd); else executor.execute(cmd, new DefaultExecuteResultHandler()); log.debug(cmd.toString()); LineIterator li = IOUtils.lineIterator(dis, "UTF-8"); if (li != null) { executorMap.put("executor", executor); executorMap.put("stdOut", li); } } catch (Exception e) { log.error(e.getCause() + ":" + e.getMessage() + "[" + cmd + "]"); } return executorMap; }