To find the number of processes running in a machine and print those in table format
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import java.io.BufferedReader; import java.io.InputStreamReader; public class NoofProcess { public static void main(String[] args) { try { // Process p = Runtime.getRuntime().exec("cmd /c tasklist /v"); Process p = Runtime.getRuntime().exec( "tasklist.exe /nh /v" ); BufferedReader stdInput = new BufferedReader( new InputStreamReader(p.getInputStream())); String input, output = "" ; while ((input = stdInput.readLine()) != null ) { output += input; System.out.println(input); } stdInput.close(); } catch (Exception k) { k.printStackTrace(); } } } |