Package org.apache.commons.exec

Examples of org.apache.commons.exec.DefaultExecutor


  public static String detectNodeCommand() {
    for (String nodeCmd : nodeCommands) {
      CommandLine cmdLine = CommandLine.parse(nodeCmd);
      cmdLine.addArguments("--version");

      DefaultExecutor executor = new DefaultExecutor();

      try {
        if (executor.execute(cmdLine) == 0) {
          return nodeCmd;
        }
      } catch (IOException e) {
        //Keep testing.
      }
View Full Code Here


  private boolean executeScript(String nodeJsFile, String scriptName, String[] params) throws IOException {
    CommandLine cmdLine = CommandLine.parse(nodeJsFile);
    cmdLine.addArgument(scriptName, false);
    cmdLine.addArguments(params, false);
    DefaultExecutor executor = new DefaultExecutor();
    try {
      return executor.execute(cmdLine) == 0;
    } catch (ExecuteException e) {
      return e.getExitValue() == 0;
    }
  }
View Full Code Here

    }

    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();

    ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
    Executor executor = new DefaultExecutor();

    ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    PumpStreamHandler streamHandler = new PumpStreamHandler(stdout);

    executor.setExitValue(1);
    executor.setStreamHandler(streamHandler);
    executor.setWatchdog(watchdog);

    try {
      executor.execute(cmdLine, resultHandler);
      logger.debug("executed commandLine '{}'", commandLine);
    } catch (ExecuteException e) {
      logger.error("couldn't execute commandLine '" + commandLine + "'",
          e);
    } catch (IOException e) {
View Full Code Here

        return cmdLine;
    }

    public static void launchContrailServer(int port) throws Exception {
        try {
            DefaultExecutor exec = new DefaultExecutor();
            int exitValues[] = {1};
            exec.setExitValues(exitValues);
            
            String workingDir = System.getProperty("user.dir");
            String path = workingDir + "/../../config/api-server/tests/";
            File f = new File(path);
            exec.setWorkingDirectory(f);
            exec.setStreamHandler(new PumpStreamHandler(new ByteArrayOutputStream()));
            CommandLine cmd = buildServerLaunchCmd(port);
            ExecuteResultHandler handler = null;
            exec.execute(cmd, handler);
            /* sleep 5 seconds for server to get started */
            Thread.sleep(5000);
        } catch (Exception e) {
            s_logger.debug(e);
            String cause = e.getMessage();
View Full Code Here

    }

    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();

    ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
    Executor executor = new DefaultExecutor();

    ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    PumpStreamHandler streamHandler = new PumpStreamHandler(stdout);

    executor.setExitValue(1);
    executor.setStreamHandler(streamHandler);
    executor.setWatchdog(watchdog);

    try {
      executor.execute(cmdLine, resultHandler);
      logger.debug("executed commandLine '{}'", commandLine);
    } catch (ExecuteException e) {
      logger.error("couldn't execute commandLine '" + commandLine + "'", e);
    } catch (IOException e) {
      logger.error("couldn't execute commandLine '" + commandLine + "'", e);
View Full Code Here

    CommandLine cmd = new CommandLine(cmdlist[0]);
    for (int i = 1; i < cmdlist.length; i++) {
      cmd.addArgument(cmdlist[i]);
    }

    DefaultExecutor exec = new DefaultExecutor();
    exec.execute(cmd);
  }
View Full Code Here

      if (StringUtils.isBlank(cmdItem) == false) {
        cmd.addArgument(cmdItem);
      }
    }

    DefaultExecutor executor = new DefaultExecutor();

    executor.setExitValue(0);
    if (StringUtils.isBlank(workDir) == false) {
      executor.setWorkingDirectory(new File(workDir));
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    PumpStreamHandler streamHandler = new PumpStreamHandler(out, out);
    if (streamHandler != null) {
      executor.setStreamHandler(streamHandler);
    }

    try {
      if (resultHandler == null) {
        executor.execute(cmd, environment);
      } else {
        executor.execute(cmd, environment, resultHandler);
      }
    }catch(ExecuteException e) {
     
      // @@@@
      // failed to run command
View Full Code Here

TOP

Related Classes of org.apache.commons.exec.DefaultExecutor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.