我需要获取正在运行的任务的进程ID。我不确定为什么下面的代码失败了。每次我将代码作为独立运行时它都没有响应。
Map<String,String> checkRunningProcess(){
Map<String,String>processPid = new HashMap<String,String>();
try{
String line,processName;
Process p = Runtime.getRuntime().exec("tasklist.exe /fo csv /nh");
BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream()));
while((line = input.readLine())!=null){
String all[] = line.split(",");
all[0] = all[0].replace("\"","");
all[1] = all[1].replace("\"", "");
//System.out.println(all[0]+all[1]);
processPid.put(all[0],all[1]);
}
}catch(Exception err){
err.printStackTrace();
}
return processPid;
}