Java Data Type Tutorial - Java Runtime.exec(String command, String [] envp)








Syntax

Runtime.exec(String command, String [] envp) has the following syntax.

public Process exec(String command,  String [] envp)  throws IOException

Example

In the following code shows how to use Runtime.exec(String command, String [] envp) method.

// ww w .  j a  v  a  2 s  .c om

public class Main {

   public static void main(String[] args) {
      try {

        String[] envArray = new String[2];
        envArray[0]="";
        envArray[1]="";
         // create a process and execute notepad.exe and currect environment
         Process process = Runtime.getRuntime().exec("notepad.exe", envArray);


      } catch (Exception ex) {
         ex.printStackTrace();
      }

   }
}