java의 (Runtime.getRuntime()).exec 을 이용해서 리눅스의 top 실행 결과를 받고 싶습니다.
아래와 같이 실행했지만
Process process = (Runtime.getRuntime()).exec("top"); InputStream in = process.getInputStream();
결과를 받을수 없는데요...
어떻게 하면 top의 결과를 받을수 있을지 알려주시면 감사하겠습니다.
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(); } } }
텍스트 포맷에 대한 자세한 정보
<code>
<blockcode>
<apache>
<applescript>
<autoconf>
<awk>
<bash>
<c>
<cpp>
<css>
<diff>
<drupal5>
<drupal6>
<gdb>
<html>
<html5>
<java>
<javascript>
<ldif>
<lua>
<make>
<mysql>
<perl>
<perl6>
<php>
<pgsql>
<proftpd>
<python>
<reg>
<spec>
<ruby>
<foo>
[foo]
import
댓글 달기