skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Thursday, September 20, 2012

Printing no of Process running in a table format

Posted by Admin at 11:47 AM – 0 comments
 

To find the number of processes running in a machine and print those in table format


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



Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger