Package org.apache.commons.exec

Examples of org.apache.commons.exec.Executor


    public static NginxCompileParameters extract(VirtualFile from) throws PlatformDependentTools.ThisIsNotNginxExecutableException {

        NginxCompileParameters result = new NginxCompileParameters();

        Executor executor = new DefaultExecutor();
        ByteArrayOutputStream os = new ByteArrayOutputStream();

        try {
            executor.setStreamHandler(new PumpStreamHandler(os, os));
            executor.execute(CommandLine.parse(from.getPath() + " -V"));
        } catch (IOException e) {
            throw new PlatformDependentTools.ThisIsNotNginxExecutableException(e);
        }

        String output = os.toString();
View Full Code Here


    if(StringUtils.isBlank(execCommand)){
      warn(out, "No command need execute.");
      return;
    }
   
    Executor executor = new DefaultExecutor();
        executor.setWorkingDirectory(site.getParentFile());

        CommandLine command = CommandLine.parse(execCommand);
       
        out.println("========================");
        info(out, String.format("Execute command: %s",  command.toString()));
        out.println("========================");
        LogOutputStream outputStream = new LogOutputStream() {
            protected void processLine(String line, int level){
                log.info(String.format("Command logged an out: %s", line));
                out.println(line);
            }
        };
        LogOutputStream errorStream = new LogOutputStream() {
            protected void processLine(String line, int level){
                log.error(String.format("Command logged an error: %s", line));
                out.println(line);
            }
        };
       
        PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, errorStream);
        executor.setStreamHandler(streamHandler);
        executor.setProcessDestroyer(processDestroyer);
       
//        (new Thread(new Runnable(){
//            public void run(){
//                try{
//                    executor.execute(command);
//                }
//                catch(Exception e) {
//                    log.warn(String.format("Command exited with error %s", e.getMessage()));
//                }
//            }
//        })).start();
 
    executor.execute(command);
  }
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

     * @return a reader containing the output of the process
     * @throws IOException starting the process failed
     */
    protected BufferedReader runProcEnvCommand() throws IOException {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final 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

            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

                log.info("Process execution complete, exit code=" + result);
            }
        };

        final String vmOptions = System.getProperty("jar.executor.vm.options");
        final Executor e = new DefaultExecutor();
        if (this.workingDirectory != null) {
            e.setWorkingDirectory(this.workingDirectory);
        }
        final CommandLine cl = new CommandLine(javaExecutable);
        if (vmOptions != null && vmOptions.length() > 0) {
            // TODO: this will fail if one of the vm options as a quoted value with a space in it, but this is
            // not the case for common usage patterns
            for (String option : StringUtils.split(vmOptions, " ")) {
                cl.addArgument(option);
            }
        }
        cl.addArgument("-jar");
        cl.addArgument(jarToExecute.getAbsolutePath());
        cl.addArgument("-p");
        cl.addArgument(String.valueOf(serverPort));
        log.info("Executing " + cl);
        e.setStreamHandler(new PumpStreamHandler());
        e.setProcessDestroyer(new ShutdownHookProcessDestroyer());
        e.execute(cl, h);
    }
View Full Code Here

                }
            }

            CommandLine commandLine = getExecutablePath( enviro, workingDirectory );

            Executor exec = new DefaultExecutor();

            String[] args = new String[commandArguments.size()];
            for ( int i = 0; i < commandArguments.size(); i++ )
            {
                args[i] = (String) commandArguments.get( i );
            }

            commandLine.addArguments( args, false );

            exec.setWorkingDirectory( workingDirectory );

            fillSuccessCodes(exec);
           
            // this code ensures the output gets logged vai maven logging, but at the same time prevents
            // partial line output, like input prompts.
View Full Code Here

    @Override
    public boolean run(boolean displayCmd, boolean throwFailure) throws Exception {
        List<String> cmd = buildCommand();
        displayCmd(displayCmd, cmd);
        Executor exec = new DefaultExecutor();

        //err and out are redirected to out
        if (!_redirectToLog) {
          exec.setStreamHandler(new PumpStreamHandler(System.out, System.err, System.in));
        } else {
            exec.setStreamHandler(new PumpStreamHandler(new LogOutputStream() {
                private LevelState _previous = new LevelState();
               
                @Override
                protected void processLine(String line, int level) {
                  try {
                    _previous = LogProcessorUtils.levelStateOf(line, _previous);
                    switch (_previous.level) {
                    case ERROR:
                      requester.getLog().error(line);
                      break;
                    case WARNING:
                      requester.getLog().warn(line);
                      break;
                    default:
                      requester.getLog().info(line);
                      break;
                    }
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                }
            }));
        }

        CommandLine cl = new CommandLine(cmd.get(0));
        for (int i = 1; i < cmd.size(); i++) {
            cl.addArgument(cmd.get(i), false);
        }
        try {
            int exitValue = exec.execute(cl);
            if (exitValue != 0) {
                if (throwFailure) {
                    throw new MojoFailureException("command line returned non-zero value:" + exitValue);
                }
                return false;
View Full Code Here

     */
    public static NginxCompileParameters extract(VirtualFile from) throws PlatformDependentTools.ThisIsNotNginxExecutableException {

        NginxCompileParameters result = new NginxCompileParameters();

        Executor executor = new DefaultExecutor();
        ByteArrayOutputStream os = new ByteArrayOutputStream();

        try {
            executor.setStreamHandler(new PumpStreamHandler(os, os));
            executor.execute(CommandLine.parse(from.getPath() + " -V"));
        } catch (IOException e) {
            throw new PlatformDependentTools.ThisIsNotNginxExecutableException(e);
        }

        String output = os.toString();
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);
            handleResult(exitValue, documentName, scannerOutput);
        } catch (IOException e) {
            // perhaps the antivirus executable was not found...
            // we omit the stack exception, because it tends to be uninteresting
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.