private Executor createExecutor(File workingDirectory, long timeoutInSeconds) { DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(workingDirectory); executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); // Fixes #41 if (timeoutInSeconds > 0) { executor.setWatchdog(new ExecuteWatchdog(timeoutInSeconds * 1000)); } return executor; }
ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); Executor executor = new DefaultExecutor();
ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog);
@Override public int getProcessId() { Map<Object, Object> newEnv = this.copyEnvironmentVariables(); DefaultExecutor executor = new DefaultExecutor(); ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); if (this.doExecution(executor, new CommandLine(this.muleBin).addArgument("status"), newEnv) == 0) { Matcher matcher = STATUS_PATTERN.matcher(outputStream.toString()); if (matcher.find()) { return Integer.parseInt(matcher.group(3)); } else { throw new MuleControllerException("bin/mule status didn't return the expected pattern: " + STATUS); } } else { throw new MuleControllerException("Mule Runtime is not running"); } }
private String computePoT(File input) throws IOException, TikaException { CommandLine cmdLine = new CommandLine("pooled-time-series"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); cmdLine.addArgument("-f"); cmdLine.addArgument(input.getAbsolutePath()); LOG.trace("Executing: {}", cmdLine); DefaultExecutor exec = new DefaultExecutor(); exec.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); exec.setWatchdog(watchdog); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); exec.setStreamHandler(streamHandler); int exitValue = exec .execute(cmdLine, EnvironmentUtils.getProcEnvironment()); return outputStream.toString("UTF-8"); }
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; }
private int executeSyncCommand(String command, String[] args, Map<Object, Object> newEnv, int timeout) throws MuleControllerException { CommandLine commandLine = new CommandLine(muleBin); commandLine.addArgument(command); commandLine.addArguments(args, false); DefaultExecutor executor = new DefaultExecutor(); ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); executor.setStreamHandler(new PumpStreamHandler()); return doExecution(executor, commandLine, newEnv); }
Closer closer = Closer.create(); ExecuteWatchdog watchDog = new ExecuteWatchdog(TimeUnit.MINUTES.toMillis(10)); StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw);
private ExecuteWatchdog createWatchdog() { return (_timeOut > 0L) ? new ExecuteWatchdog(_timeOut) : null; }
public static ExecuteWatchdog createTimeoutWatchdog(TimeUnit timeunit, int timeout) { ExecuteWatchdog timeoutWatchdog = new ExecuteWatchdog(timeunit.toMillis(timeout)); return timeoutWatchdog; }
public void setTimeout(int timeout) { if (timeout < 0) { throw new IllegalArgumentException("Timeout cannot be negative"); } this.timeout = timeout; watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); } }
public void setTimeout(long timeout) { watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); }
ExecuteWatchdog watchdog = new ExecuteWatchdog(1000*60*5); Process process= Runtime.getRuntime().exec("cmd"); watchdog.start(process);
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 }
String line = "your command line"; CommandLine cmdLine = CommandLine.parse(line); DefaultExecutor executor = new DefaultExecutor(); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); int exitValue = executor.execute(cmdLine); System.out.println(exitValue); System.out.println(outputStream.toString());
/** * Create {@link org.apache.commons.exec.Executor} with infinite timeout watchdog * * @return created executor */ public static Executor createExecutor() { ExecuteWatchdog watchdog = new ExecuteWatchdog(INFINITE_TIMEOUT); Executor executor = new DefaultExecutor(); executor.setExitValue(1); executor.setWatchdog(watchdog); return executor; }
private int execute(CommandLine commandLine, int timeout) throws IOException { DefaultExecutor executor = new DefaultExecutor(); ExecuteWatchdog watchdog = new ExecuteWatchdog(TimeUnit.SECONDS.toMillis(timeout)); executor.setWatchdog(watchdog); executor.setExitValue(0); return executor.execute(commandLine); }
Map map = new HashMap(); map.put("file", new File("invoice.pdf")); CommandLine cmdLine = new CommandLine("AcroRd32.exe"); cmdLine.addArgument("/p"); cmdLine.addArgument("/h"); cmdLine.addArgument("${file}"); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(1); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine);
private static DefaultExecutor getDefaultExecutor(File dir, int expectedExit, long timeout) { DefaultExecutor executor = new DefaultExecutor(); if(expectedExit != -1) { executor.setExitValue(expectedExit); } else { executor.setExitValues(null); } ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); executor.setWorkingDirectory(dir); return executor; }
protected DefaultExecutor prepareDefaultExecutor(ExecCommand execCommand) { DefaultExecutor executor = new ExecDefaultExecutor(); executor.setExitValues(null); if (execCommand.getWorkingDir() != null) { executor.setWorkingDirectory(new File(execCommand.getWorkingDir()).getAbsoluteFile()); } if (execCommand.getTimeout() != ExecEndpoint.NO_TIMEOUT) { executor.setWatchdog(new ExecuteWatchdog(execCommand.getTimeout())); } executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); return executor; }