How to get a list of current open windows/process with Java?

后端 未结 14 1537
抹茶落季
抹茶落季 2020-11-22 05:20

Does any one know how do I get the current open windows or process of a local machine using Java?

What I\'m trying to do is: list the current open task, windows or

14条回答
  •  春和景丽
    2020-11-22 05:53

        String line;
        Process process = Runtime.getRuntime().exec("ps -e");
        process.getOutputStream().close();
        BufferedReader input =
                new BufferedReader(new InputStreamReader(process.getInputStream()));
        while ((line = input.readLine()) != null) {
            System.out.println(line); //<-- Parse data here.
        }
        input.close();

    We have to use process.getOutputStream.close() otherwise it will get locked in while loop.

提交回复
热议问题