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
2008-12-11 14:02:01