In this example we are going to execute an application using java program.
This example uses the Process class that
is contained in the lang package and extends Object
class. The method Runtime.exec() creates a native process and returns an instance of a subclass of
the Process class.
This instance is then used to control the process and to obtain the information about
the process. The Process class provides methods for performing input ,output , wait, checking the exit status
, and destroying (killing) the process.
The Runtime.exec() method may not work well for windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts.
The class Runtime contained in java.lang package and extends the Object class. Every Java application has a single instance of class Runtime. The current runtime can be obtained by using the getRuntime() method. Any application cannot create its own instance of runtime class.
The method used:
exec(String command): This method is used to execute the command. Here command is a specified system command. It can also be used to execute any .exe file.
The code of the program is given below:
The output of the program is given below:
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: July 6, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles