java执行批处理命令 获取返回 数据

版权声明:技术改变命运;http://www.qingmiaokeji.cn;微信[qing_gee] https://blog.csdn.net/huangmingleiluo/article/details/26368577
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;






public class T {


/**
* <b>描述:</b>
* @param args
* void 
* @author 张磊  2014-5-16 编写
*/
public static void main(String[] args) {
Process process;
try {
process = Runtime.getRuntime().exec("ping " + "localhost");
InputStreamReader r = new InputStreamReader(process.getInputStream());
LineNumberReader returnData = new LineNumberReader(r);


String returnMsg = "";
String line = "";
while ((line = returnData.readLine()) != null) {
System.out.println(returnData.getLineNumber()+" "+line);
returnMsg += line;
}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}




}


}
展开阅读全文

没有更多推荐了,返回首页