how to run shell command in java

how to run shell command in java
String homeDirectory = System.getProperty("user.home");
Process process;

if (isWindows) {
    process = Runtime.getRuntime()
      .exec(String.format("cmd.exe /c dir %s", homeDirectory));
} else {
    process = Runtime.getRuntime()
      .exec(String.format("sh -c ls %s", homeDirectory));
}
StreamGobbler streamGobbler = 
  new StreamGobbler(process.getInputStream(), System.out::println);
Executors.newSingleThreadExecutor().submit(streamGobbler);

int exitCode = process.waitFor();
if( exitCode == 0 ){
	System.out.println("Executed the command successlly!");
}
Sour‮w:ec‬ww.lautturi.com
Created Time:2017-09-29 13:47:23  Author:lautturi