The java.lang.Runtime.exec(String command) method executes the specified string command in a separate process. This is a convenience method. An invocation of the form exec(command) behaves in exactly the same way as the invocation exec(command, null, null).

Declaration

Following is the declaration for java.lang.Runtime.exec() method

Return Value

This method returns a new Process object for managing the subprocess

Exception

  • SecurityException -- If a security manager exists and its checkExec method doesn't allow creation of the subprocess
  • IOException -- If an I/O error occurs
  • NullPointerException -- If command is null
  • IllegalArgumentException -- If command is empty

Example

The following example shows the usage of lang.Runtime.exec() method
    
{
      
Runtime rm=Runtime.getRuntime();
rm.exec("notepad");
    
        }
   }