public static String runShell(String command){
try{
String[] commands = isLinux()?new String[]{"/bin/sh","-c",command}:new String[]{"cmd","/c",command};
Process process = Runtime.getRuntime().exec(commands);
InputStreamReader ir = new InputStreamReader(process.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String ln;
StringBuilder result = new StringBuilder();
while ((ln = input.readLine()) != null){
result.append(ln);
result.append("\n");
}
input.close();
ir.close();
return result.toString();
}
catch(Exception e){
e.printStackTrace();//log
return null;
}
}
public static boolean isLinux(){
String os = System.getProperty("os.name").toLowerCase();
if(null != os && os.contains("windows")){
return false;
}
return true;
}
 
1
public static String runShell(String command){
2
    try{
3
        String[] commands = isLinux()?new String[]{"/bin/sh","-c",command}:new String[]{"cmd","/c",command};
4
        Process process = Runtime.getRuntime().exec(commands);          
5
        InputStreamReader ir = new InputStreamReader(process.getInputStream());
6
        LineNumberReader input = new LineNumberReader(ir);
7
        String ln;
8
        StringBuilder result = new StringBuilder();
9
        while ((ln = input.readLine()) != null){           
10
            result.append(ln);
11
            result.append("\n");                       
12
        }
13
        input.close();
14
        ir.close();
15
        return result.toString();           
16
    }
17
    catch(Exception e){
18
        e.printStackTrace();//log
19
        return null;
20
    }       
21
}
22
public static boolean isLinux(){
23
    String os = System.getProperty("os.name").toLowerCase();
24
    if(null != os && os.contains("windows")){
25
        return false;
26
    }
27
    return true;
28
}

最新文章

  1. 凭吊一下ASP.NET 5,然后跨平台,越跨越开心
  2. CI框架入门1
  3. ViewPager
  4. shell脚本实现拷贝大文件显示百分比的代码分享
  5. Python入门笔记(9):元组
  6. ajax提交特殊字符的处理
  7. wp控件
  8. Build AssetBundle, missing shader.
  9. cocos2d-x之 CCSpriteBatchNode 用法总结
  10. linux 已有目录挂载磁盘
  11. Jenkins 十二: 集成 selenium 测试
  12. Broadcom网卡linux系统下无法连接到网络问题(某种情况- -||)的解决办法
  13. flume 自己定义 hbase sink 类
  14. python学习笔记之一:列表与元组
  15. jeecg入门操作—一对多表单开发
  16. Android Studio多渠道打包(二)
  17. Coding语言强弱类型且动静态类型简单解析。附图解
  18. [蓝点zigBee] CC2530 实用教程总览
  19. Django 操作Mysql数据库
  20. 关于新版OPENWRT拔PPTP的619错或PPTPD无法连接问题笔记

热门文章

  1. python之路——网络编程
  2. 【志银】NYOJ《题目860》又见01背包
  3. Python 黑魔法(持续收录)
  4. c语言为什么效率高
  5. GYM - 101147 K.Touristic Trip
  6. 股神小L [贪心]
  7. BZOJ5301 [Cqoi2018]异或序列 【莫队】
  8. 3.2 Lucene实战:一个简单的小程序
  9. [原]C++拾遗
  10. Linux临时增加swap空间