Java Runtime.exec(String [] cmdarray)

Syntax

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

public Process exec(String [] cmdarray)  throws IOException

Example

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


/*  ww w  .  j  a  v  a  2 s  .c o m*/
public class Main {

   public static void main(String[] args) {
      try {
         String[] cmdArray = new String[2];
         // first argument is the program to open
         cmdArray[0] = "notepad.exe";

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

         // create a process and execute cmdArray
         Process process = Runtime.getRuntime().exec(cmdArray);

      } 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