Java Runtime.exec(String [] cmdarray, String [] envp)

Syntax

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

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

Example

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


//  w w w. ja v  a2s . c o  m
public class Main {

   public static void main(String[] args) {
      try {
         String[] cmdArray = new String[2];

         // the program to open
         cmdArray[0] = "notepad.exe";

         // txt file to open with notepad
         cmdArray[1] = "data.txt";


         String[] envArray = new String[2];
         envArray[0]="";
         envArray[1]="";
         Process process = Runtime.getRuntime().exec(cmdArray,envArray);


      } 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