请原谅,这是我第一次提出问题。我正在寻找使用Java打印当前在我的计算机上运行的所有应用程序的方法。打印所有正在运行的应用程序Java
例如:
Google Chrome
Microsoft Word
Microsoft Outlook
Netbeans 8.0.2
Etc.
目前,我开始一个新的进程和运行命令ps -e然后分析其输出。虽然我认为我通过使用命令行正处于正确的轨道,但我认为我需要一个不同的命令。 这里是我的代码:
try {
String line;
Process p = Runtime.getRuntime().exec("ps -e");
BufferedReader input =
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
for(int i = 0; i < line.length(); i++){
try{
if(line.substring(i, i + 13).equals(".app/Contents")){
//System.out.println(line.substring(i - 5, i + 3));
int j = 0;
String app = "";
while(!(line.charAt(i + j) == '/')){
app = app + line.charAt(i + j);
//System.out.print(line.charAt(i + j));
j--;
}
String reverse = new StringBuffer(app).reverse().toString();
System.out.println(reverse);
//System.out.println("");
}/*System.out.println(line.substring(i, i + 13));*/}catch(Exception e){}
}
//System.out.println(line); //<-- Parse data here.
}
input.close();
} catch (Exception err) {
err.printStackTrace();
}
所以,这是正确的做法,是那里只是一个不同的命令,我需要使用或是否有更好的方法的整体?
http://stackoverflow.com/questions/54686/how-to-get-a-list-of-current-open-windows-process-with-java类似于你在做什么 –
这就是我开始了,但这只会给我所有的流程。我尝试使用.app/Contents解析所有内容,但这不起作用。 – dsiegler19