ProcessBuilder: command(String... command) : ProcessBuilder « java.lang « Java by API






ProcessBuilder: command(String... command)

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.Map;

public class MainClass {
  public static void main(String args[]) throws Exception {
    ProcessBuilder launcher = new ProcessBuilder();
    Map<String, String> environment = launcher.environment();
    launcher.redirectErrorStream(true);
    launcher.directory(new File("c:\\"));

    environment.put("name", "var");
    launcher.command("notepad.exe");
    Process p = launcher.start(); // And launch a new process
    BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = output.readLine()) != null)
      System.out.println(line);

    // The process should be done now, but wait to be sure.
    p.waitFor();

  }
}

           
       








Related examples in the same category

1.ProcessBuilder: directory(File directory)
2.ProcessBuilder: environment()
3.ProcessBuilder: redirectErrorStream(boolean redirectErrorStream)
4.ProcessBuilder: start()