Posts

Showing posts with the label Apache Commons Exec

Executing External Programs From Java

Image
     Using java, you can open external programs such as notepad, command prompt, etc. But executing external processes from java is inherently operating system dependent and requires the developer to know the specific behaviors pertaining to the platform.        Here is the two ways to execute  1. Using java.lang.Runtime 2. Using Apache commons exec library. 1. Using java.lang.Runtime :                   Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.        Runtime rt = Runtime.getRuntime(); you can execute a program by supplying the command related to that program to the exec method of runtime object.       rt.exec("notepad");     ...