Java ProcessBuilder run command with parameter

Introduction

The following code executes the Windows text editor notepad.

Notice that it specifies the name of the file to edit as an argument.

public class Main {
  public static void main(String args[]) {

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



PreviousNext

Related