private int execute(final Logger logger, final OutputStream stdout, final OutputStream stderr) throws ProcessExecutionException { logger.debug("Executing command line {}", commandLine); try { ExecuteStreamHandler streamHandler = new PumpStreamHandler(stdout, stderr); executor.setStreamHandler(streamHandler); int exitValue = executor.execute(commandLine, environment); logger.debug("Exit value {}", exitValue); return exitValue; } catch (ExecuteException e) { if (executor.getWatchdog() != null && executor.getWatchdog().killedProcess()) { throw new ProcessExecutionException("Process killed after timeout"); } throw new ProcessExecutionException(e); } catch (IOException e) { throw new ProcessExecutionException(e); } }
LOG.error("Command: " + cmd + " failed. res=" + res, ex); if(watchdog.killedProcess()) { String msg = " was terminated due to timeout(" + timeout + "ms). See " + AppConfig .EXEC_TIMEOUT_NAME + " property";
public static int executeCommand(String command, String... envVars) throws IOException { CommandLine cmdLine = CommandLine.parse(command); DefaultExecutor executor = new DefaultExecutor(); Map<String, String> env = addEnvProperties(envVars); ExecuteWatchdog watchDog = new ExecuteWatchdog(TIMEOUT); executor.setWatchdog(watchDog); executor.setStreamHandler(new PumpStreamHandler()); int result = executor.execute(cmdLine, env); if (executor.isFailure(result)) { if (watchDog.killedProcess()) { throw new RuntimeException("Reached timeout while running: " + cmdLine); } throw new RuntimeException("Process failed with return code [" + result + "]: " + cmdLine); } return result; }
if (watchDog.killedProcess()) logger.error("The command {} was killed after 10 minutes", fullCommand); pw.flush();
@Override public void onProcessFailed(final ExecuteException e) { super.onProcessFailed(e); if (watchdog != null && watchdog.killedProcess()) { LOG.warn("Installation killed by watchdog"); } else { LOG.warn("Installation failed due to [{}]", e.getMessage()); } } }
ExecuteWatchdog watchdog = new ExecuteWatchdog(30000); Executer exec = new Executer(myloghandler, watchdog); exec.setCommandLine(mycmdline); int exitvalue = exec.execute(); if (Execute.isFailure(exitvalue) && watchdog.killedProcess()) { // it was killed on purpose by the watchdog }
if (watchdog.killedProcess()) { throw new IOException("Watchdog had to kill script process");
/** * Executes the given command synchronously. * * @param command The command to execute. * @param processInput Input provided to the process. * @return The result of the execution, or empty if the process does not terminate within the timeout set for this executor. * @throws IOException if the process execution failed. */ public Optional<ProcessResult> execute(String command, String processInput) throws IOException { ByteArrayOutputStream processErr = new ByteArrayOutputStream(); ByteArrayOutputStream processOut = new ByteArrayOutputStream(); DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler(createStreamHandler(processOut, processErr, processInput)); ExecuteWatchdog watchDog = new ExecuteWatchdog(TimeUnit.SECONDS.toMillis(timeoutSeconds)); executor.setWatchdog(watchDog); executor.setExitValues(successExitCodes); int exitCode; try { exitCode = executor.execute(CommandLine.parse(command)); } catch (ExecuteException e) { exitCode = e.getExitValue(); } return (watchDog.killedProcess()) ? Optional.empty() : Optional.of(new ProcessResult(exitCode, processOut.toString(), processErr.toString())); }
int exitValue = executor.execute(cmdLine); if (executor.isFailure(exitValue) && timeoutWatchdog.killedProcess()) { if (timeoutWatchdog.killedProcess()) { logger.debug("A timeout occured while executing a process"); logger.debug("The command is " + cmdString);
if ( watchdog.killedProcess() ) { System.err.println( "Killed batch process: " + name + " (timeout of " + timeout + " exceeded)" );
private static void internalExecute(CommandLine cmdLine, OutputStream outputStream, File workingDirectory) throws IOException { Executor executor = getExecutor(); ExecuteWatchdog watchdog = getExecuteWatchdog(); executor.setWatchdog(watchdog); if (workingDirectory != null) { executor.setWorkingDirectory(workingDirectory); } // set allowed exit values (0 is actually the default) executor.setExitValue(0); PumpStreamHandler psh = new PumpStreamHandler(outputStream); executor.setStreamHandler(psh); executor.execute(cmdLine); if (watchdog.killedProcess()) { throw new ExecuteException(String.format("Watchdog killed Sencha Cmd process after %s ms.", MAX_EXECUTION_TIME), 0); } }
LOG.error("Command: " + cmd + " failed. res=" + res, ex); if(watchdog.killedProcess()) { String msg = " was terminated due to timeout(" + timeout + "ms). See " + AppConfig .EXEC_TIMEOUT_NAME + " property";
public static void run(LineConsumer outputHandler, Map<String, String> envVarsForApp, CommandLine command, File projectRoot, long timeout) throws ProjectCannotStartException { long startTime = logStartInfo(command, projectRoot); ExecuteWatchdog watchDog = new ExecuteWatchdog(timeout); Executor executor = createExecutor(outputHandler, command, projectRoot, watchDog); try { int exitValue = executor.execute(command, envVarsForApp); if (executor.isFailure(exitValue)) { String message = watchDog.killedProcess() ? "Timed out waiting for " + command : "Exit code " + exitValue + " returned from " + command; throw new ProjectCannotStartException(message); } } catch (Exception e) { String message = "Error running: " + fullPath(projectRoot) + "> " + StringUtils.join(command.toStrings(), " "); outputHandler.consumeLine(message); outputHandler.consumeLine(e.toString()); throw new ProjectCannotStartException(message, e); } logEndTime(command, startTime); }
if (watchDog.killedProcess()) logger.error("The command {} was killed after 10 minutes", cli); pw.flush(); throw new CCMException(
boolean failed = executor.isFailure(exitValue); systemCommand.setFailed(failed); boolean killed = failed && watchdog.killedProcess(); systemCommand.setKilled(killed); systemCommand.setOutput(baos.toString());
return executor.execute(cli, getMergedEnvironment(configuration)); } catch (ExecuteException e) { if (watchdog != null && watchdog.killedProcess()) { log.error("Timeout " + forkedProcessTimeoutInSeconds + " s exceeded. Process was killed.");