package test;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
/**
* @author 作者 路飞:
* @version 创建时间:2013-6-18 上午11:44:03
* 类说明 执行命令行并打印返回结果
*/
public class Demo{
public static void main(String args[]){
Runtime rn = Runtime.getRuntime();
Process p = null;
String cmdStr = "";
try{
cmdStr = "arp -a";
p = rn.exec(cmdStr);
//结果自己解析
System.out.println( new String(read(p.getInputStream())));
}catch( Exception e ){
e.printStackTrace();
}
}
public static byte[] read(InputStream inStream) throws Exception{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while( (len = inStream.read(buffer)) != -1){
outputStream.write(buffer, 0, len);
}
inStream.close();
return outputStream.toByteArray();
}
}