Java Runtime.exec(String command, String [] envp, File dir)

Syntax

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

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

Example

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


/*from   w  ww .j a  v  a2s . c om*/


import java.io.File;

public class Main {

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


         File dir = new File("C:/");

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


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

   }
}




















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable