9/25/2009

JAVA - Listar/Recuperar processos em execução do Windows

// Checar a existencia do executável : tasklist.exe

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class ListarProcessosWindows {


public static void main(String[] args) {

try {

String command = "c:\\windows\\system32\\tasklist.exe";
Process child = Runtime.getRuntime().exec(command);

InputStream in = child.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
ArrayList saida = new ArrayList();
String linha = "";
while( ( linha = reader.readLine() ) != null ){
String[] str = linha.split(" ");
saida.add(str[0]);
}
in.close();

for (String s : saida) {
System.out.println(s);
}

} catch (IOException e) {
}


}


}