package com.liwei.http;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by Liwei on 2016/1/27.
 *
 * 参考资料:http://segmentfault.com/a/1190000000372192
 *
 * 提供超时功能:http://segmentfault.com/a/1190000000372535
 *
 *
 */
/**
 * 列出所有的进程信息
 */
public class Test05 {
    static Process proc = null;
    static BufferedReader br = null;

    public static void main(String[] args) {
        try {
            proc = Runtime.getRuntime().exec("tasklist");
            // 注意:在这里修改编码
            br = new BufferedReader(
                    new InputStreamReader(proc.getInputStream(), "GBK"));
            String line;
            System.out.println("列出所有正在运行的进程信息:");
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }finally {
            if (br != null) {
                try {
                    br.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if(proc!=null){
                proc.destroy();
            }
        }
    }
}