Example usage for org.apache.commons.exec PumpStreamHandler start

List of usage examples for org.apache.commons.exec PumpStreamHandler start

Introduction

In this page you can find the example usage for org.apache.commons.exec PumpStreamHandler start.

Prototype

public void start() 

Source Link

Document

Start the Threads.

Usage

From source file:net.hasor.maven.ExecMojo.java

protected int executeCommandLine(Executor exec, CommandLine commandLine, Map<String, String> enviro,
        FileOutputStream outputFile) throws ExecuteException, IOException {
    BufferedOutputStream bos = new BufferedOutputStream(outputFile);
    PumpStreamHandler psh = new PumpStreamHandler(bos);
    exec.setStreamHandler(psh);/*from w  w w  .j  a va2 s  .co  m*/
    int result;
    try {
        psh.start();
        result = exec.execute(commandLine, enviro);
    } finally {
        psh.stop();
    }
    return result;
}

From source file:net.hasor.maven.ExecMojo.java

protected int executeCommandLine(Executor exec, CommandLine commandLine, Map<String, String> enviro,
        OutputStream out, OutputStream err) throws ExecuteException, IOException {
    //note: dont use BufferedOutputStream here since it delays the outputs MEXEC-138
    PumpStreamHandler psh = new PumpStreamHandler(out, err, System.in);
    exec.setStreamHandler(psh);//from w  w w .j  a va  2  s  .  c  o m
    int result;
    try {
        psh.start();
        result = exec.execute(commandLine, enviro);
    } finally {
        psh.stop();
    }
    return result;
}

From source file:kr.motd.maven.exec.ExecMojo.java

protected int executeCommandLine(Executor exec, CommandLine commandLine, Map<String, String> enviro,
        FileOutputStream outputFile) throws ExecuteException, IOException {
    BufferedOutputStream bos = new LineBufferedOutputStream(outputFile);
    PumpStreamHandler psh = new PumpStreamHandler(bos);
    exec.setStreamHandler(psh);//from   www .  j  a v a  2 s .c om

    int result;
    try {
        psh.start();
        result = exec.execute(commandLine, enviro);
    } finally {
        psh.stop();
    }
    return result;
}

From source file:kr.motd.maven.exec.ExecMojo.java

protected int executeCommandLine(Executor exec, CommandLine commandLine, Map<String, String> enviro,
        OutputStream out, OutputStream err) throws ExecuteException, IOException {
    BufferedOutputStream bosStdOut = new LineBufferedOutputStream(out);
    BufferedOutputStream bosStdErr = new LineBufferedOutputStream(err);
    PumpStreamHandler psh = new PumpStreamHandler(bosStdOut, bosStdErr, System.in);
    exec.setStreamHandler(psh);/* w  ww. j  a  v  a  2s. com*/

    int result;
    try {
        psh.start();
        result = exec.execute(commandLine, enviro);
    } finally {
        psh.stop();
    }
    return result;
}

From source file:org.codehaus.mojo.exec.ExecMojo.java

protected int executeCommandLine(Executor exec, final CommandLine commandLine, Map<String, String> enviro,
        final PumpStreamHandler psh) throws ExecuteException, IOException {
    exec.setStreamHandler(psh);//from www .j  a  v  a 2 s.co m

    int result;
    try {
        psh.start();
        if (async) {
            if (asyncDestroyOnShutdown) {
                exec.setProcessDestroyer(getProcessDestroyer());
            }

            exec.execute(commandLine, enviro, new ExecuteResultHandler() {
                public void onProcessFailed(ExecuteException e) {
                    getLog().error("Async process failed for: " + commandLine, e);
                }

                public void onProcessComplete(int exitValue) {
                    getLog().info("Async process complete, exit value = " + exitValue + " for: " + commandLine);
                    try {
                        psh.stop();
                    } catch (IOException e) {
                        getLog().error("Error stopping async process stream handler for: " + commandLine, e);
                    }
                }
            });
            result = 0;
        } else {
            result = exec.execute(commandLine, enviro);
        }
    } finally {
        if (!async) {
            psh.stop();
        }
    }
    return result;
}

From source file:org.stem.ExternalNode.java

private DefaultExecuteResultHandler startStemProcess(CommandLine commandLine, Map env)
        throws MojoExecutionException {
    try {//from  w  ww.  ja  v a2s. co  m
        DefaultExecutor exec = new DefaultExecutor();
        DefaultExecuteResultHandler execHandler = new DefaultExecuteResultHandler();
        exec.setWorkingDirectory(nodeDir);
        exec.setProcessDestroyer(new ShutdownHookProcessDestroyer());

        LogOutputStream stdout = new MavenLogOutputStream(log);
        LogOutputStream stderr = new MavenLogOutputStream(log);

        log.debug("Executing command line: " + commandLine);

        PumpStreamHandler streamHandler = new PumpStreamHandler(stdout, stderr);
        streamHandler.start();
        exec.setStreamHandler(streamHandler);

        exec.execute(commandLine, env, execHandler);
        //            try
        //            {
        //                execHandler.waitFor();
        //            }
        //            catch (InterruptedException e)
        //            {
        //                e.printStackTrace();
        //            }
        return execHandler;
    } catch (IOException e) {
        throw new MojoExecutionException("Command execution failed.", e);
    }
}