我想使用java代码获取运行进程的路径名和参数。有没有解决方案?
答案 0 :(得分:3)
例如,在Windows上,一种可能性是封装system call to TASKLIST.EXE
从代码中摘录:
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(""")));
}
}
您应该使用tasklist /V
,因为它附带了流程的参数。
答案 1 :(得分:1)
您可以使用SIGAR框架,它为您提供对Linux,FreeBSD,Windows,Solaris,AIX,HP-UX和Mac OSX的本机支持