List of usage examples for org.apache.commons.exec DefaultExecutor DefaultExecutor
public DefaultExecutor()
From source file:de.akquinet.innovation.play.maven.Play2RunMojo.java
public void execute() throws MojoExecutionException { String line = getPlay2().getAbsolutePath(); CommandLine cmdLine = CommandLine.parse(line); cmdLine.addArguments(getPlay2SystemPropertiesArguments(), false); cmdLine.addArgument("run"); DefaultExecutor executor = new DefaultExecutor(); // As where not linked to a project, we can't set the working directory. // So it will use the directory where mvn was launched. executor.setExitValue(0);// www . jav a 2s . c om try { executor.execute(cmdLine, getEnvironment()); } catch (IOException e) { // Ignore. } }
From source file:com.muk.ext.process.ProcessExecutor.java
public int runCommandLine(CommandLine cmdLine, long maxWaitTimeInMillis) throws IOException { ExecuteWatchdog processWatchDog = new ExecuteWatchdog(maxWaitTimeInMillis); Executor executor = new DefaultExecutor(); executor.setExitValue(0);/*from www . java 2 s . c om*/ executor.setWatchdog(processWatchDog); int result = 1; result = executor.execute(cmdLine); return result; }
From source file:com.codeabovelab.dm.common.utils.ProcessUtils.java
public static int executeCommand(String command, ExecuteWatchdog watchdog, OutputStream outputStream, OutputStream errorStream, InputStream inputStream, Map<String, String> env) { CommandLine cmdLine = CommandLine.parse(command); DefaultExecutor executor = new DefaultExecutor(); if (outputStream == null) { outputStream = new LogOutputStream() { @Override//from w w w . j a va 2 s . com protected void processLine(String s, int i) { log.error(s); } }; } if (errorStream == null) { errorStream = new LogOutputStream() { @Override protected void processLine(String s, int i) { log.error(s); } }; } executor.setStreamHandler(new PumpStreamHandler(outputStream, errorStream, inputStream)); executor.setExitValues(new int[] { 0, 1 }); if (watchdog != null) { executor.setWatchdog(watchdog); } int exitValue; try { exitValue = executor.execute(cmdLine, env); } catch (IOException e) { exitValue = 1; LOGGER.error("error executing command", e); } return exitValue; }
From source file:com.stratio.ingestion.utils.IngestionUtils.java
public static DefaultExecuteResultHandler executeBash(String command) throws IOException { CommandLine cmdLine = CommandLine.parse("bash"); cmdLine.addArgument("-c", false); cmdLine.addArgument(command, false); DefaultExecutor executor = new DefaultExecutor(); ByteArrayOutputStream outputStreamAgentStart = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(outputStreamAgentStart)); DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler(); executor.execute(cmdLine, handler);/* w w w. j a v a 2s . c o m*/ return handler; }
From source file:eu.creatingfuture.propeller.blocklyprop.propeller.PropellerLoad.java
protected List<String> getPorts(String executable) { List<String> ports = new ArrayList<>(); try {// w w w .j av a 2s .co m CommandLine cmdLine = new CommandLine(executable); cmdLine.addArgument("-P"); DefaultExecutor executor = new DefaultExecutor(); //executor.setExitValues(new int[]{451, 301}); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); try { exitValue = executor.execute(cmdLine); } catch (ExecuteException ee) { exitValue = ee.getExitValue(); logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue); return ports; } finally { output = outputStream.toString(); } /* if (exitValue == 301) { return ports; } */ // System.out.println("output: " + output); Scanner scanner = new Scanner(output); while (scanner.hasNextLine()) { ports.add(scanner.nextLine()); } return ports; } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); return null; } }
From source file:eu.creatingfuture.propeller.webLoader.propeller.PropellerLoad.java
protected List<String> getPorts(String executable) { List<String> ports = new ArrayList<String>(); try {/* w w w . j a v a 2 s. c o m*/ CommandLine cmdLine = new CommandLine(executable); cmdLine.addArgument("-P"); DefaultExecutor executor = new DefaultExecutor(); //executor.setExitValues(new int[]{451, 301}); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); try { exitValue = executor.execute(cmdLine); } catch (ExecuteException ee) { exitValue = ee.getExitValue(); logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue); return ports; } finally { output = outputStream.toString(); } /* if (exitValue == 301) { return ports; } */ // System.out.println("output: " + output); Scanner scanner = new Scanner(output); while (scanner.hasNextLine()) { ports.add(scanner.nextLine()); } return ports; } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); return null; } }
From source file:com.magnet.tools.tests.WebLogicStepDefs.java
public static void ensureDeployApp(String url, String name, String location) throws Exception { Executor exec = new DefaultExecutor(); CommandLine cl = new CommandLine(getScriptsDir() + File.separator + REDEPLOY_WLS_APP_SCRIPT); if (getArchetypeSettings() != null && getArchetypeSettings().length() != 0) { cl.addArgument(getArchetypeSettings()); }//from w w w . j a v a 2s . c o m cl.addArgument(url); cl.addArgument(name); cl.addArgument(location); cl.setSubstitutionMap(getSubstitutionMap()); int exitValue = exec.execute(cl); String msg = String.format("Server running at %s failed to deploy app %s at %s", url, name, expandVariables(location)); ensureBuildSuccessful("redeploy.log"); Assert.assertEquals(msg, 0, exitValue); }
From source file:com.boulmier.machinelearning.jobexecutor.job.Job.java
public void start() throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final DefaultExecutor exec = new DefaultExecutor(); final ExecuteWatchdog wd = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); final PumpStreamHandler output = new PumpStreamHandler(out); final DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler(); exec.setWatchdog(wd);//from w w w . j a v a2s .com exec.setStreamHandler(output); exec.execute(cl, handler); JobExecutor.logger.info("Running job " + jobid); new Thread(new Runnable() { @Override public void run() { try { handler.waitFor(); Computer.ComputeProperties properties = Computer.ComputeProperties.buildFromRequest(req); new SenderComputer(new StorageComputer(out.toString(), properties)).compute(); JobExecutor.logger.info("Job complete " + jobid); } catch (InterruptedException ex) { exec.getWatchdog().destroyProcess(); JobExecutor.logger.error( "Job (" + jobid + ") has been destroyed due to internal error " + ex.getMessage()); } } }).start(); }
From source file:com.dangdang.ddframe.job.api.type.script.executor.ScriptJobExecutor.java
public ScriptJobExecutor(final JobFacade jobFacade) { super(jobFacade); executor = new DefaultExecutor(); }
From source file:io.github.binout.wordpress2html.writer.Html2AsciidocConverter.java
private void execute(CommandLine cmdLine) throws IOException { DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0);/* w ww .j a v a2s . c o m*/ ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine); if (exitValue != 0) { throw new RuntimeException("Pandoc is not installed !"); } }