Source:
<code>public static ProcessResult executeCommands(final List<String> commands, final Duration timeOut) { Preconditions.checkArgument(commands != null && timeOut != null); int retVal = -2; String stdOutput = null; String stdError = null; try { final Process process = new ProcessBuilder().command(commands).start(); <START> if (timeOut.getStandardSeconds() > 0) { <END> final Future<Integer> processFuture = processExecutor.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { return process.waitFor(); } }); try { retVal = processFuture.get(timeOut.getStandardSeconds(), TimeUnit.SECONDS); } catch (ExecutionException | TimeoutException e) { retVal = -1; stdError = "Operation timed out, aborted"; if (LOG.isTraceEnabled()) { LOG.trace("Failed to complete the requested command within timeout: " + e.getMessage()); } } finally { if (Strings.isNullOrEmpty(stdError)) { stdOutput = readStream(process.getInputStream()); stdError = readStream(process.getErrorStream()); } } } else { retVal = process.waitFor(); stdOutput = readStream(process.getInputStream()); stdError = readStream(process.getErrorStream()); } process.destroy(); if (LOG.isTraceEnabled()) { LOG.trace("Process standard output: " + stdOutput); LOG.trace("Process standard error output: " + stdError); } } catch (IOException | InterruptedException e) { stdError = e.getMessage(); LOG.error("Exception caught error running commands: " + e.getMessage()); } return new ProcessResult(stdOutput, stdError, retVal); }</code><technical_language>a command a timeout accepted</technical_language>

Target:
public ProcessResult executeCommands(final List<String> commands, final Duration timeOut) { Preconditions.checkArgument(commands != null && timeOut != null && timeOut.getStandardSeconds() > 0L && (timeOut.compareTo(DEFAULT_MAX_TIMEOUT) <= 0) && executor != null); int retVal = -2; String stdOutput = null; String stdError = null; try { final Process process = new ProcessBuilder().command(commands).start(); final Future<Integer> processFuture = executor.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { return process.waitFor(); } }); try { retVal = processFuture.get(timeOut.getStandardSeconds(), TimeUnit.SECONDS); } catch (ExecutionException e) { retVal = -2; stdError = e.getMessage(); if (LOG.isTraceEnabled()) { LOG.trace("Failed to complete the requested command due to execution error: " + e.getMessage()); } } catch (TimeoutException e) { retVal = -1; stdError = "Operation timed out, aborted"; if (LOG.isTraceEnabled()) { LOG.trace("Failed to complete the requested command within timeout: " + e.getMessage()); } } finally { if (Strings.isNullOrEmpty(stdError)) { stdOutput = CharStreams.toString(new InputStreamReader(process.getInputStream())); stdError = CharStreams.toString(new InputStreamReader(process.getErrorStream())); } process.destroy(); } if (LOG.isTraceEnabled()) { LOG.trace("Process standard output: " + stdOutput); LOG.trace("Process standard error output: " + stdError); } } catch (IOException | InterruptedException e) { stdError = e.getMessage(); LOG.error("Exception caught error running commands: " + e.getMessage()); } return new ProcessResult(stdOutput, stdError, retVal); }