IT_Programming/Java
Java로 윈도우 서비스 리스트 가져오는 방법
JJun ™
2010. 12. 29. 15:26
해당 출력내용이 스트림을 통해 line에 출력된다. 이 line String을 파싱해서 가져다 쓰면 된다.
StringBuffer message = new StringBuffer();
InputStreamReader isr = null;
BufferedReader br = null;
try
{
Process p = Runtime.getRuntime().exec(System.getenv("windir")+"\\system32\\"+"tasklist.exe");
isr = new InputStreamReader(p.getInputStream());
br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine())!= null)
{
System.out.println("msg=>"+line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if(isr!=null) try {isr.close(); } catch (IOException e) {}
if(br!=null) try { br.close();} catch (IOException e) {}
}