Execute a Windows Native Command via Java

A Windows native Command like for example "netstat" or any other should be executed inside a Java Application. The Application is able to read the output that the native command is producing.
1 answer

Execute a Windows Native Command via Java

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");
}
}