Refine search
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; }
final File dir, final ExecuteStreamHandler streams) throws IOException { setExceptionCaught(null); final Process process = this.launch(command, environment, dir); if (this.getProcessDestroyer() != null) { this.getProcessDestroyer().add(process); watchdog.start(process); watchdog.stop(); watchdog.checkException(); } catch (final IOException e) { throw e;
private ExecBean auxRun(String program, List<String> args, Map<String, String> env) throws NotAuthorizedException, ExecuteException, IOException { DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(null); ByteArrayOutputStream outStream = new MaxByteArrayOutputStream(nbytes); ByteArrayOutputStream errStream = new MaxByteArrayOutputStream(nbytes); executor.setStreamHandler(new PumpStreamHandler(outStream, errStream)); ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); res.stderr = errStream.toString(enc); try { watchdog.checkException(); if(watchdog.killedProcess()) { String msg = " was terminated due to timeout(" + timeout + "ms). See " + AppConfig .EXEC_TIMEOUT_NAME + " property";
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"); }
cmdLine = new CommandLine(cmdArray[0]); cmdLine.addArgument(cmdArray[i], false); cmdLine = CommandLine.parse(commandLine); ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); Executor executor = new DefaultExecutor(); PumpStreamHandler streamHandler = new PumpStreamHandler(stdout);
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); }
CommandLine cmdLine = new CommandLine(APP_NAME); cmdLine.addArgument("-d"); cmdLine.addArgument("${outputLocation}"); cmdLine.addArgument("-f"); cmdLine.addArgument("-o"); cmdLine.setSubstitutionMap(argMap); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine);
/** * Executes the command. * * @return Exit code. */ public final int execute() { try { final Map<String, String> envMap = EnvironmentUtils .getProcEnvironment(); envMap.put("DEBIAN_FRONTEND", "noninteractive"); envMap.putAll(env); final CommandLine command = new CommandLine("/bin/sh"); final String cmdStr = createSubCmd(); command.addArguments(new String[] { "-c", cmdStr }, false); final DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler(new PumpStreamHandler(out, err)); executor.setWorkingDirectory(workingDir); executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); executor.setWatchdog(new ExecuteWatchdog(timeoutSeconds * 1000)); return executor.execute(command, envMap); } catch (final IOException ex) { throw new RuntimeException(ex); } }
Closer closer = Closer.create(); ExecuteWatchdog watchDog = new ExecuteWatchdog(TimeUnit.MINUTES.toMillis(10)); StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); try { logger.trace("Executing: " + fullCommand); CommandLine cli = CommandLine.parse(fullCommand); Executor executor = new DefaultExecutor(); LogOutputStream outStream = new LogOutputStream() { closer.register(outStream); closer.register(errStream); ExecuteStreamHandler streamHandler = new PumpStreamHandler(outStream, errStream); executor.setStreamHandler(streamHandler); executor.setWatchdog(watchDog); if (watchDog.killedProcess()) logger.error("The command {} was killed after 10 minutes", fullCommand); pw.flush();
CommandLine cli = new CommandLine(executable); cli.addArguments(configuration.getVMArguments(), handleQuotes); cli.addArguments(new String[] { "-jar", getCanonicalPath(configuration.getLauncherJar()) }, handleQuotes); cli.addArguments(configuration.getProgramArguments(), handleQuotes); log.info("Command line:\n\t" + cli.toString()); DefaultExecutor executor = new DefaultExecutor(); ExecuteWatchdog watchdog = null; if (forkedProcessTimeoutInSeconds > 0) { watchdog = new ExecuteWatchdog(forkedProcessTimeoutInSeconds * 1000L); executor.setWatchdog(watchdog); executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); executor.setWorkingDirectory(configuration.getWorkingDirectory()); try { return executor.execute(cli, getMergedEnvironment(configuration)); } catch (ExecuteException e) { if (watchdog != null && watchdog.killedProcess()) { log.error("Timeout " + forkedProcessTimeoutInSeconds + " s exceeded. Process was killed.");
CommandLine cmdLine = new CommandLine("java"); cmdLine.addArgument("-Djava.library.path=" + dynLocalDir + "/DynamoDBLocal_lib"); cmdLine.addArgument("-jar"); cmdLine.addArgument(dynLocalDir + "/DynamoDBLocal.jar"); cmdLine.addArgument("-sharedDb"); watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); Executor executor = new DefaultExecutor(); executor.setWatchdog(watchdog); executor.execute(cmdLine, resultHandler);
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); }
public void execute(CommandLine cmd, @Nullable File workingDirectory) throws InterruptedException, IOException { LOG.info("executing command {}", cmd.toString()); final ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000); final Executor executor = new org.apache.commons.exec.DefaultExecutor(); executor.setWatchdog(watchdog); if (workingDirectory != null) { executor.setWorkingDirectory(workingDirectory); } LOG.debug("workdir: {}", executor.getWorkingDirectory()); final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ByteArrayOutputStream err = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(out, err)); executor.execute(cmd, resultHandler); resultHandler.waitFor(); final int exitCode = resultHandler.getExitValue(); if (out.size() > 0) { LOG.info(out.toString()); } if (exitCode != 0) { throw new IOException(err.size() == 0 ? "command '" + cmd + "' didn't succeed" : err.toString()); } } }
CommandLine commandLine = new CommandLine(execAndArgs[0]); commandLine.addArguments(Arrays.copyOfRange(execAndArgs, 1, execAndArgs.length)); Executor executor = new DefaultExecutor(); executor.setExitValue(0); ByteArrayOutputStream baes = new ByteArrayOutputStream(); ByteArrayInputStream bais = new ByteArrayInputStream((stdInLine + "\n").getBytes()); PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(baos, baes, bais); executor.setStreamHandler(pumpStreamHandler); ExecuteWatchdog watchdog = new ExecuteWatchdog(timeoutUnit.toMillis(timeout)); executor.setWatchdog(watchdog); if (watchdog.killedProcess()) { throw new IOException("Watchdog had to kill script process");
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; }
@Override public void call() { PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(stdOut, stdErr, stdIn); CommandLine commandLine; commandLine = new CommandLine(jobRequest.getTokenizedCommand().get(0)); commandLine.addArguments(arguments, false); Executor executor = new DefaultExecutor(); executor.setStreamHandler(pumpStreamHandler); executor.setWatchdog(watchdog); watchdog.destroyProcess();
CommandLine cmdLine = new CommandLine("bin/logisland-launch-spark-job"); cmdLine.addArgument("--agent"); cmdLine.addArgument("http://0.0.0.0:8081"); cmdLine.addArgument("--job"); cmdLine.addArgument(jobId); ExecuteWatchdog watchdog = new ExecuteWatchdog(5 * 60 * 1000); Executor executor = new DaemonExecutor(); executor.setWatchdog(watchdog); PumpStreamHandler psh = new PumpStreamHandler(stdout); executor.setExitValue(0); executor.setStreamHandler(psh);
public void stop() { watchdog.destroyProcess(); final CommandLine cmdLine = new CommandLine(bashFile.getAbsolutePath()); final DefaultExecutor executor = new DefaultExecutor(); int exitValue = 0; exitValue = executor.execute(cmdLine); } catch (final IOException ex) { LOGGER.error("Unable to execute bigtable emulator kill script", ex);
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; }
/** * 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; }