java의 (Runtime.getRuntime()).exec 을 이용해 top 결과를 받고 싶습니다.
글쓴이: bumworld / 작성시간: 화, 2008/01/15 - 10:10오전
java의 (Runtime.getRuntime()).exec 을 이용해서 리눅스의 top 실행 결과를 받고 싶습니다.
아래와 같이 실행했지만
Process process = (Runtime.getRuntime()).exec("top");
InputStream in = process.getInputStream();
결과를 받을수 없는데요...
어떻게 하면 top의 결과를 받을수 있을지 알려주시면 감사하겠습니다.
Forums:


import
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class TOP { public static void main(String[] args) { Runtime rt = Runtime.getRuntime(); Process p = null; try { p = rt.exec("top -b -n 1"); BufferedReader in = new BufferedReader(new InputStreamReader(p .getInputStream())); String cl = null; while ((cl = in.readLine()) != null) { System.out.print(cl); System.out.print("\n"); } System.out.print("\n"); in.close(); } catch (IOException e) { e.printStackTrace(); } } }