How to get a list of running processes in Java and check if a process is running?

Arc*_*e K 0 java process

So I want to check if "join.me" the program is running when my application opens.

https://www.join.me/

That is the site to the download.

Process joinme = Runtime.getRuntime().exec("join.me");
Run Code Online (Sandbox Code Playgroud)

This doesn't seem to work.

Any idea?

Or I want to cycle through an array of processes to see what the "join.me" process is called.

Cheers.

Dim*_*San 5

您需要使用 Microsoft 的 OOTBtasklist.exe实用程序,该实用程序随 Windows 一起提供,可在C:\windows\system32\tasklist.exe. 以及以下行:

Process p = Runtime.getRuntime().exec("tasklist.exe");
Run Code Online (Sandbox Code Playgroud)

将执行它。然后你可以读取这个字符串,Scanner直到它有下一行。以下代码为您提供系统上运行的正在运行的程序(前台和后台应用程序)的列表:

public static void main(String[] args) throws IOException {
    Process process = Runtime.getRuntime().exec("tasklist.exe");
    Scanner scanner = new Scanner(new InputStreamReader(process.getInputStream()));
    while (scanner.hasNext()) {
        System.out.println(scanner.nextLine());
    }
    scanner.close();
}
Run Code Online (Sandbox Code Playgroud)

你会得到这样的输出: 在此处输入图片说明