I hava used Standard Java to solve this. Detailed Comments are below:
public class ExecuteCmd {
public static void main(String[] args) throws Exception {
//the process to be started -> netstat -> shows some statistics about open connections
String[] processArgs = new String[]{"netstat"};
//the process itself
Process process = new ProcessBuilder(processArgs).start();
//get only the inputStream, because we don't want to send command's to process
BufferedReader processReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String received;
while ((received = processReader.readLine()) != null){
System.out.println(received);
}
processReader.close(); //clase it
System.out.println("process ended");
}
}