用java执行shell命令
2013-02-22 21:18
423 查看
public static String getPhysicalAddress() { Process p = null; try { // 执行ipconfig /all命令 p = new ProcessBuilder("ipconfig", "/all").start(); } catch (IOException e) { return ""; } byte[] b = new byte[1024]; int readbytes = -1; StringBuffer sb = new StringBuffer(); // 读取进程输出值 InputStream in = p.getInputStream(); try { while ((readbytes = in.read(b)) != -1) { sb.append(new String(b, 0, readbytes)); } } catch (IOException e1) { } finally { try { in.close(); } catch (IOException e2) { } } return sb.toString(); }
转自:java通过ProcessBuilder执行本地shell命令 获取ip配置信息
- java代码库 - 云代码 http://yuncode.net/code/c_50a5e9ef2258c96
相关文章推荐
- DOS命令 SHELL命令 BAT命令 执行 java 的 class文件和Jar文件
- Java远程执行Shell命令
- Android或Java应用中如何以默认用户或root用户执行Shell命令
- windows 下 java程序jsch连接远程linux服务器执行shell命令
- java执行命令(cmd,shell)
- 通过Java代码执行shell命令/脚本
- java本地调用cmd,shell命令,远程调用Linux执行命令方法总结
- java执行shell命令中有空格的处理方法
- java通过ssh连接服务器执行shell命令详解及实例
- java本地调用cmd,shell命令,远程调用Linux执行命令方法总结
- java 执行linux命令或shell脚本方法
- Android Java执行Shell命令
- java调用shell命令并获取执行结果的示例
- java调用shell命令并获取执行结果
- java调用shell命令并获取执行结果
- java执行windows、shell命令
- Java开发之调用shell命令并获取执行结果(Mac)
- paip.执行shell cmd 命令uapi java php python总结
- linux 下 java 执行 shell 命令
- Java实现远程联接服务器执行shell命令