Package org.apache.commons.exec

Examples of org.apache.commons.exec.CommandLine


    // Only run for N milliseconds
    int timeout = appConf.getInt(AppConfig.EXEC_TIMEOUT_NAME, 0);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
    executor.setWatchdog(watchdog);

    CommandLine cmd = makeCommandLine(program, args);

    LOG.info("Running: " + cmd);
    ExecBean res = new ExecBean();

    if(Shell.WINDOWS){
      //The default executor is sometimes causing failure on windows. hcat
      // command sometimes returns non zero exit status with it. It seems
      // to hit some race conditions on windows.
      env = execEnv(env);
      String[] envVals = new String[env.size()];
      int i=0;
      for( Entry<String, String> kv : env.entrySet()){
        envVals[i++] = kv.getKey() + "=" + kv.getValue();
        LOG.info("Setting " +  kv.getKey() + "=" + kv.getValue());
      }

      Process proc;
      synchronized (WindowsProcessLaunchLock) {
        // To workaround the race condition issue with child processes
        // inheriting unintended handles during process launch that can
        // lead to hangs on reading output and error streams, we
        // serialize process creation. More info available at:
        // http://support.microsoft.com/kb/315939
        proc = Runtime.getRuntime().exec(cmd.toStrings(), envVals);
      }

      //consume stderr
      StreamOutputWriter errorGobbler = new
        StreamOutputWriter(proc.getErrorStream(), "ERROR", errStream);
View Full Code Here


  private CommandLine makeCommandLine(String program,
                    List<String> args)
    throws NotAuthorizedException, IOException {
    String path = validateProgram(program);
    CommandLine cmd = new CommandLine(path);
    if (args != null)
      for (String arg : args)
        cmd.addArgument(arg, false);

    return cmd;
  }
View Full Code Here

  public int exec(final String command, OutputStream out, OutputStream err)
      throws IOException
  {
    LOG.debug("Execute command : {}", command);

    CommandLine cmdLine = CommandLine.parse(command);
    DefaultExecutor executor = new DefaultExecutor();
    executor.setStreamHandler(new PumpStreamHandler(out, err));

    int exitValue = executor.execute(cmdLine);
    LOG.debug("Execution finished with exit code : {}", exitValue);
View Full Code Here

    // Only run for N milliseconds
    int timeout = appConf.getInt(AppConfig.EXEC_TIMEOUT_NAME, 0);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
    executor.setWatchdog(watchdog);

    CommandLine cmd = makeCommandLine(program, args);

    LOG.info("Running: " + cmd);
    ExecBean res = new ExecBean();

    if(Shell.WINDOWS){
      //The default executor is sometimes causing failure on windows. hcat
      // command sometimes returns non zero exit status with it. It seems
      // to hit some race conditions on windows.
      env = execEnv(env);
      String[] envVals = new String[env.size()];
      int i=0;
      for( Entry<String, String> kv : env.entrySet()){
        envVals[i++] = kv.getKey() + "=" + kv.getValue();
        LOG.info("Setting " +  kv.getKey() + "=" + kv.getValue());
      }

      Process proc;
      synchronized (WindowsProcessLaunchLock) {
        // To workaround the race condition issue with child processes
        // inheriting unintended handles during process launch that can
        // lead to hangs on reading output and error streams, we
        // serialize process creation. More info available at:
        // http://support.microsoft.com/kb/315939
        proc = Runtime.getRuntime().exec(cmd.toStrings(), envVals);
      }

      //consume stderr
      StreamOutputWriter errorGobbler = new
        StreamOutputWriter(proc.getErrorStream(), "ERROR", errStream);
View Full Code Here

  private CommandLine makeCommandLine(String program,
                    List<String> args)
    throws NotAuthorizedException, IOException {
    String path = validateProgram(program);
    CommandLine cmd = new CommandLine(path);
    if (args != null)
      for (String arg : args)
        cmd.addArgument(arg, false);

    return cmd;
  }
View Full Code Here

        }
    }

    private void doScan(File file, String documentName) {
        Stopwatch stop = new Stopwatch().start();
        CommandLine cmdLine = buildCommandLine(file);
        ByteArrayOutputStream scannerOutput = new ByteArrayOutputStream();
        Executor executor = buildExecutor(scannerOutput);
        try {
            int exitValue = executor.execute(cmdLine);
            log.debug("{} to scan file: '{}'", stop, documentName);
View Full Code Here

            throw new RuntimeException(msg);
        }
    }

    private CommandLine buildCommandLine(File file) {
        CommandLine cmdLine = new CommandLine(SCANNER_NAME);
        if (USING_CLAM) {
            cmdLine.addArguments(CLAMDSCAN_ARGS, false);
        }
        cmdLine.addArgument(file.getPath(), false);
        return cmdLine;
    }
View Full Code Here

        this.file = file;
    }

    @Test
    public void testIndexHtmlIsValid() throws ExecuteException, IOException {
        CommandLine cmdLine = CommandLine.parse("tidy");
        cmdLine.addArguments(new String[] {"-output", "/dev/null", "-quiet"});
        cmdLine.addArgument(file.getAbsolutePath());
        DefaultExecutor executor = new DefaultExecutor();
        int exitValue = executor.execute(cmdLine);
        assertEquals(0, exitValue);
    }
View Full Code Here

    String classpath = manifestClasspath(sourceDirectory, outputDirectory, compileClasspathElements);

    final String javaExecutable = getJavaExecutable();
    getLog().debug("Java exectuable used:  " + javaExecutable);
    getLog().debug("Clojure manifest classpath: " + classpath);
    CommandLine cl = null;

    if (ExecutionMode.INTERACTIVE == executionMode && SystemUtils.IS_OS_WINDOWS && spawnInteractiveConsoleOnWindows) {
      Scanner sc = new Scanner(windowsConsole);
      Pattern pattern = Pattern.compile("\"[^\"]*\"|'[^']*'|[\\w'/]+");
      cl = new CommandLine(sc.findInLine(pattern));
      String param;
      while ((param = sc.findInLine(pattern)) != null) {
        cl.addArgument(param);
      }
      cl.addArgument(javaExecutable);
    } else {
      cl = new CommandLine(javaExecutable);
    }

    if (vmargs != null) {
      cl.addArguments(vmargs, false);
    }

    cl.addArgument("-Dclojure.compile.path=" + escapeFilePath(outputDirectory), false);

    if (warnOnReflection) cl.addArgument("-Dclojure.compile.warn-on-reflection=true");

    cl.addArguments(clojureOptions, false);

    cl.addArgument("-jar");
    File jar;
    if (prependClasses != null && prependClasses.size() > 0) {
      jar = createJar(classpath, prependClasses.get(0));
      cl.addArgument(jar.getAbsolutePath(), false);
      List<String> allButFirst = prependClasses.subList(1, prependClasses.size());
      cl.addArguments(allButFirst.toArray(new String[allButFirst.size()]));
      cl.addArgument(mainClass);
    } else {
      jar = createJar(classpath, mainClass);
      cl.addArgument(jar.getAbsolutePath(), false);
    }


    if (clojureArgs != null) {
      cl.addArguments(clojureArgs, false);
    }

    getLog().debug("Command line: " + cl.toString());

    Executor exec = new DefaultExecutor();
    Map<String, String> env = new HashMap<String, String>(System.getenv());
//        env.put("path", ";");
//        env.put("path", System.getProperty("java.home"));
View Full Code Here

public class ExecWorkItemHandler implements WorkItemHandler {

  public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
    String command = (String) workItem.getParameter("Command");
    CommandLine commandLine = CommandLine.parse(command);
    DefaultExecutor executor = new DefaultExecutor();
    try {
      executor.execute(commandLine);
      manager.completeWorkItem(workItem.getId(), null);
    } catch (Throwable t) {
View Full Code Here

TOP

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

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.