Example usage for java.lang ProcessBuilder redirectInput

List of usage examples for java.lang ProcessBuilder redirectInput

Introduction

In this page you can find the example usage for java.lang ProcessBuilder redirectInput.

Prototype

public Redirect redirectInput() 

Source Link

Document

Returns this process builder's standard input source.

Usage

From source file:Test.java

public static void main(String[] args) throws Exception {
    File commands = new File("C:/Projects/ProcessCommands.txt");
    File output = new File("C:/Projects/ProcessLog.txt");
    File errors = new File("C:/Projects/ErrorLog.txt");

    ProcessBuilder pb = new ProcessBuilder("cmd");
    System.out.println(pb.redirectInput().toString());
    System.out.println(pb.redirectOutput().toString());
    System.out.println(pb.redirectError().toString());

    pb.redirectInput(commands);// www  .  j  a  va 2 s  . c o  m
    pb.redirectError(errors);
    pb.redirectOutput(output);
    System.out.println(pb.redirectInput().toString());
    System.out.println(pb.redirectOutput().toString());
    System.out.println(pb.redirectError().toString());

    pb.start();
}

From source file:Main.java

public static void main(String[] args) {

    // create a new list of arguments for our process
    String[] list = { "notepad.exe", "test.txt" };

    // create the process builder
    ProcessBuilder pb = new ProcessBuilder(list);
    try {//from   w ww.  ja v  a 2 s .c  o m

        pb.start();
        System.out.println(pb.redirectInput());
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:io.snappydata.hydra.cluster.SnappyTest.java

public void executeProcess(ProcessBuilder pb, File logFile) {
    Process p = null;//from   w  ww . java  2s.c  om
    try {
        pb.redirectErrorStream(true);
        pb.redirectError(ProcessBuilder.Redirect.PIPE);
        pb.redirectOutput(ProcessBuilder.Redirect.appendTo(logFile));
        p = pb.start();
        assert pb.redirectInput() == ProcessBuilder.Redirect.PIPE;
        assert pb.redirectOutput().file() == logFile;
        assert p.getInputStream().read() == -1;
        int rc = p.waitFor();
        if (rc == 0) {
            Log.getLogWriter().info("Executed successfully");
        } else {
            Log.getLogWriter().info("Failed with exit code: " + rc);
        }
    } catch (IOException e) {
        throw new TestException(
                "Exception occurred while starting the process:" + pb + "\nError Message:" + e.getMessage());
    } catch (InterruptedException e) {
        throw new TestException("Exception occurred while waiting for the process execution:" + p
                + "\nError Message:" + e.getMessage());
    }
}

From source file:xbdd.webapp.resource.feature.PrintPDF.java

public void generatePDF(final List<String> commands) throws IOException {
    final ProcessBuilder probuilder = new ProcessBuilder(commands);
    probuilder.redirectError();/*from  w  w w .  j a v  a2 s.  co m*/
    probuilder.redirectOutput();
    probuilder.redirectInput();
    final Process process = probuilder.start();
    try {
        process.waitFor();
    } catch (final InterruptedException e) {
        e.printStackTrace();
    }
    process.destroy();
}