Package org.apache.commons.exec

Examples of org.apache.commons.exec.Executor


       
        if (clojureArgs != null) {
            cl.addArguments(clojureArgs, false);
        }
       
        Executor exec = new DefaultExecutor();
        Map<String,String> env = new HashMap<String,String>(System.getenv());
        env.put("path", ";");
        env.put("path", System.getProperty("java.home"));
       
        ExecuteStreamHandler handler = new CustomPumpStreamHandler(System.out, System.err, System.in);
        exec.setStreamHandler(handler);
       
        int status;
        try {
            status = exec.execute(cl, env);
        } catch (ExecuteException e) {
            status = e.getExitValue();
        } catch(IOException e) {
            status = 1;
        }
View Full Code Here


            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"));

        ExecuteStreamHandler handler = new PumpStreamHandler(System.out, System.err, System.in);
        exec.setStreamHandler(handler);
        exec.setWorkingDirectory(getWorkingDirectory());

        int status;
        try {
            status = exec.execute(cl, env);
        } catch (ExecuteException e) {
            status = e.getExitValue();
        } catch (IOException e) {
            status = 1;
        }
View Full Code Here

        return null;
    }

    private String exec(File workingDir, org.apache.commons.exec.CommandLine cmdLine) throws Exception {
        Executor executor = new DefaultExecutor();
        org.apache.commons.io.output.ByteArrayOutputStream buffer = new org.apache.commons.io.output.ByteArrayOutputStream();
        NullOutputStream nullOs = new NullOutputStream();
        PumpStreamHandler streamHandler = new PumpStreamHandler(nullOs, buffer);
        executor.setWorkingDirectory(workingDir);
        executor.setStreamHandler(streamHandler);
        String result = "";

        try {
            exec(executor, cmdLine);
            result = buffer.toString();
View Full Code Here

            }
        }
    }

    protected void killPid(String pid) throws IOException {
        Executor executor = new DefaultExecutor();
        executor.setWorkingDirectory(getBinDir());
        PumpStreamHandler streamHandler = new PumpStreamHandler(createNullOutputStream(), createNullOutputStream());
        executor.setStreamHandler(streamHandler);
        org.apache.commons.exec.CommandLine commandLine;

        commandLine = new org.apache.commons.exec.CommandLine("kill").addArgument(pid);
        executor.execute(commandLine);
    }
View Full Code Here

        executor.execute(commandLine);
    }

    protected boolean isUnixPidRunning(String pid) {

        Executor executor = new DefaultExecutor();
        executor.setWorkingDirectory(getBinDir());
        PumpStreamHandler streamHandler = new PumpStreamHandler(createNullOutputStream(), createNullOutputStream());
        executor.setStreamHandler(streamHandler);
        org.apache.commons.exec.CommandLine commandLine;
        commandLine = new org.apache.commons.exec.CommandLine("kill").addArgument("-0").addArgument(pid);

        boolean isRunning = true; // assume it is running
        try {
            int code = executor.execute(commandLine);
            if (code != 0) {
                isRunning = false;
            }
        } catch (ExecuteException ee) {
            log.debug("kill -0 for pid [" + pid + "] threw exception with exit value [" + ee.getExitValue() + "]");
View Full Code Here

    final ByteArrayOutputStream err = new ByteArrayOutputStream();
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final CommandLine cmdLine = new CommandLine(kill_cmd);
    cmdLine.addArguments(kill_cmd_params);
    cmdLine.addArguments(pid);
    final Executor executor = new DefaultExecutor();
    executor.setExitValue(1);
    final DefaultExecuteResultHandler derh = new DefaultExecuteResultHandler();
//    executor.setProcessDestroyer(MPlayerFileService.PROCESS_SHUTDOWN_HOOK);
    executor.setStreamHandler(new PumpStreamHandler(out, err));
    try {
      logger.info("execute " + kill_cmd_log + " " + pid);
      executor.execute(cmdLine, derh);
      derh.waitFor();
      return true;
    } catch (final ExecuteException e) {
      logger.error("error on " + kill_cmd_log + pid, e);
    } catch (final IOException e) {
View Full Code Here

  private List<ProcessToWatch> getProcessList() {
    final ByteArrayOutputStream err = new ByteArrayOutputStream();
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final CommandLine cmdLine = new CommandLine(list_cmd);
    cmdLine.addArguments(list_cmd_params);
    final Executor executor = new DefaultExecutor();
    executor.setExitValue(1);

    final DefaultExecuteResultHandler derh = new DefaultExecuteResultHandler();
    executor.setProcessDestroyer(MPlayerFileService.PROCESS_SHUTDOWN_HOOK);
    executor.setStreamHandler(new PumpStreamHandler(out, err));
    try {
      logger.info("execute " + list_cmd_log);
      executor.execute(cmdLine, derh);
      derh.waitFor();
     
    } catch (final ExecuteException e) {
      logger.error("error on " + list_cmd_log, e);
    } catch (final IOException e) {
View Full Code Here

//    if (! path.toLowerCase().endsWith("mts")) {
      final CommandLine cmdLine = new CommandLine(this.mplayer);
      cmdLine.addArguments(this.arguments);
      cmdLine.addArgument(this.path, false);
//      ExecuteWatchdog watchdog = new ExecuteWatchdog(30*1000);
      final Executor executor = new DefaultExecutor();
      executor.setExitValue(1);
//      executor.setWatchdog(watchdog);
//      executor.setProcessDestroyer(MPlayerFileService.PROCESS_SHUTDOWN_HOOK);
      executor.setStreamHandler(new PumpStreamHandler(this.out, this.err));
      executor.setWorkingDirectory(this.tempFolder);
      executor.execute(cmdLine, this);
     
//    } else {
//      throw new ExecuteException("mts will not work with mplayer -identify", 0);
//    }
    return this;
View Full Code Here

//    if (! path.toLowerCase().endsWith("mts")) {
      final CommandLine cmdLine = new CommandLine(this.mplayer);
      cmdLine.addArguments(this.arguments);
      cmdLine.addArgument(this.path, false);
//      ExecuteWatchdog watchdog = new ExecuteWatchdog(5*1000);
      final Executor executor = new DefaultExecutor();
      executor.setExitValue(1);
//      executor.setWatchdog(watchdog);
//      executor.setProcessDestroyer(MPlayerFileService.PROCESS_SHUTDOWN_HOOK);
      executor.setStreamHandler(new PumpStreamHandler(this.out, this.err));
      executor.execute(cmdLine, this);

//    } else {
//      throw new ExecuteException("mts will not work with mplayer -identify", 0);
//    }
    return this;
View Full Code Here

     * @return a reader containing the output of the process
     * @throws IOException starting the process failed
     */
    protected BufferedReader runProcEnvCommand() throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Executor exe = new DefaultExecutor();
        exe.setStreamHandler(new PumpStreamHandler(out));
        // ignore the exit value - Just try to use what we got
        exe.execute(getProcEnvCommand());
        return new BufferedReader(new StringReader(toString(out)));
    }
View Full Code Here

TOP

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

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.