how to execute shell commands in java/**
* @author lautturi.com
* Java example: execute shell command / command line in java
*/
import java.util.*;
import java.io.IOException;
public class Lautturi {
public static void main(String[] args) {
ProcessBuilder pb = new ProcessBuilder("ping", "localhost");
pb.inheritIO();
try {
Process p = pb.start();
int exitStatus = p.waitFor();
System.out.println(exitStatus);
}
catch (InterruptedException | IOException x) {
x.printStackTrace();
}
}
}
Sourceal.www:utturi.com