Example usage for java.lang ProcessBuilder ProcessBuilder

List of usage examples for java.lang ProcessBuilder ProcessBuilder

Introduction

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

Prototype

public ProcessBuilder(String... command) 

Source Link

Document

Constructs a process builder with the specified operating system program and arguments.

Usage

From source file:MainClass.java

public static void main(String args[]) {

    try {//from  www.  j  av a  2s.  c o m
        ProcessBuilder proc = new ProcessBuilder("notepad.exe testfile");
        proc.start();
    } catch (Exception e) {
        System.out.println("Error executing notepad.");
    }
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<String>();
    list.add("notepad.exe");

    ProcessBuilder pb = new ProcessBuilder(list);

    List<String> list2 = new ArrayList<String>();
    list2.add("text.txt");

    // set the command list
    pb.command(list2);/*w  w  w . j  a va 2s  . co m*/

    System.out.println(pb.command());
}

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

    // check if errorstream is redirected
    System.out.println("" + pb.redirectErrorStream());
}

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

    // Redirect the error stream
    pb.redirectErrorStream(true);//from   w  ww .  ja  v  a  2  s. c  o m
    System.out.println(pb.redirectErrorStream());
}

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

    // set the command list
    pb.command(list);/*www .j a va 2 s  .  co m*/

    // print the new command list
    System.out.println(pb.command());
}

From source file:Main.java

public static void main(String args[]) throws IOException {

    Process process = new ProcessBuilder(args).start();
    InputStream is = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line;//from  w ww  .j  av a 2s. com

    System.out.printf("Output of running %s is:", Arrays.toString(args));

    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }

}

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

    // set the working directory of the process
    pb.directory(new File("C:/"));
    System.out.println(pb.directory());
}

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

    // get the environment of the process
    Map<String, String> env = pb.environment();

    // get the system drive of the environment
    System.out.println(env);/*from w ww  .  j  a va2  s .  c o  m*/
    System.out.println(env.get("SystemDrive"));
}

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  . j a v  a2 s.c  o  m*/
        // start the subprocess
        System.out.println("Starting the process..");
        pb.start();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

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 {// w ww.ja  va2  s. c o  m

        ProcessBuilder.Redirect re = pb.redirectError();
        pb.start();
        System.out.println(re);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}