Java呼び出し実行Linuxシステムコマンド
940 ワード
Java Runtime Linux , :
Runtime.getRuntime().exec(command)
, Runtime.exec
, Process ( :Runtime.getRuntime().exec(command)
Process ) 。
Runtime.exec
, IO( stdin,stdou,stderr)
Process.getOutputStream(),Process.getInputStream(),
Process.getErrorStream() 。
stream , linux :
try {
String[] cmd = new String[]{”/bin/sh”, “-c”, ” ls “};
Process ps = Runtime.getRuntime().exec(cmd);
BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append(”
”);
}
String result = sb.toString();
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
:http://www.linuxidc.com/Linux/2010-07/27376.htm