Execute the shell commands using ProcessBuilder in Java

We can execute the shell commands using the Java.lang.ProcessBuilder class in Java.Lets see the program to execute the shell commands.

Java Program to execute the shell commands:

Java Program to execute command prompt commands

If you want to run the command prompt commands,you can use the cmd.exe instead of sh in the builder command list.It helps java to identify the environment to run the given commands.

Output: