tags:

views:

446

answers:

3

I want to get the path name and arguments of running processes using java code. Is there any solution?

+3  A: 

For instance, on Windows, one possibility is to encapsulate the system call to TASKLIST.EXE

Extract from the code:

Process p = Runtime.getRuntime().exec("tasklist.exe /fo csv /nh");
      BufferedReader input = new BufferedReader
          (new InputStreamReader(p.getInputStream()));
      while ((line = input.readLine()) != null) {
          if (!line.trim().equals("")) {
              // keep only the process name
              line = line.substring(1);
              processes.add(line.substring(0, line.indexOf(""")));
          }

      }

You should use tasklist /V though, since it comes with the parameters of the processes.

VonC
+1  A: 

You could use the SIGAR framework, which gives you native support for Linux, FreeBSD, Windows, Solaris, AIX, HP-UX and Mac OSX

zehrer
A: 

how to get the real path from precess list