Java Process run operating system command

Introduction

The following example uses exec() to launch notepad.

// Demonstrate exec().
public class Main {
  public static void main(String args[]) {
    Runtime r = Runtime.getRuntime();
    Process p = null;/*  w  ww .j a va2 s.  c  om*/

    try {
      p = r.exec("notepad");
    } catch (Exception e) {
      System.out.println("Error executing notepad.");
    }
  }
}



PreviousNext

Related