Example usage for org.apache.commons.exec ExecuteStreamHandler setProcessOutputStream

List of usage examples for org.apache.commons.exec ExecuteStreamHandler setProcessOutputStream

Introduction

In this page you can find the example usage for org.apache.commons.exec ExecuteStreamHandler setProcessOutputStream.

Prototype

void setProcessOutputStream(InputStream is) throws IOException;

Source Link

Document

Install a handler for the output stream of the subprocess.

Usage

From source file:org.estatio.webapp.services.other.EstatioOtherServices.java

@Programmatic
String execute(String command) {

    int exitValue = 1;
    CommandLine commandLine = CommandLine.parse(command);
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(0);/*from  www. j av a  2 s  . com*/
    ExecuteStreamHandler handler = executor.getStreamHandler();

    ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    PumpStreamHandler psh = new PumpStreamHandler(stdout);
    executor.setStreamHandler(psh);

    try {
        handler.setProcessOutputStream(System.in);
    } catch (IOException e) {

    }

    try {
        exitValue = executor.execute(commandLine);
    } catch (ExecuteException e) {
        return e.getMessage();
    } catch (IOException e) {
        return e.getMessage();
    }
    return stdout.toString();
}