Executing System commands in Java—ref
One of the nice features of Java language is that it provides you the opportunity to execute native system commands and in this tutorial we will see how to use Runtime class in a quite simple program to execute commands like ipconfig
As an example consider the below snippet
As you can see in the above class we first need to access the runtime environment. This is done with
Runtime.getRuntime()
method. We also need to create an OS process in order to execute the system command. As you can see this process is created with
exec()
method of the Runtime class. Finally we need to create a BufferedReader in order to read the input stream of the process and display the output in our console.
Executing ipconfig command will give us the below output
ref: http://www.java-only.com/LoadTutorial.javaonly?id=117