不灭的焱

革命尚未成功,同志仍须努力

作者:php-note.com  发布于:2018-09-17 16:33  分类:Java基础 
public static void main(String[] args) {
    String keyWord = "chrome.exe";

    Runtime runtime = Runtime.getRuntime();

    try {
        Process process = runtime.exec("cmd /c Tasklist");

        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));

        String s;
        while ((s = in.readLine()) != null) {
            s = s.toLowerCase();
            if (s.startsWith(keyWord)) {
                System.out.println("==========>" + keyWord);
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}