根据命令执行

  /**
     * 判断什么操作系统
     */
    public String osName = System.getProperty("os.name");

    /**
     * 根据命令执行,
     * @param cmdstr
     * @param isNeedReturn
     * @return list
     * @throws Exception
     */
    public List execute(String cmdstr, boolean isNeedReturn) throws Exception {
        //存储结果
        List lineList = new ArrayList();
        String[] cmdarray;
        if (osName.startsWith("Windows")) {
            cmdarray = new String[]{"cmd", "/c", cmdstr};
        } else {
            cmdarray = new String[]{"/bin/bash", "-c", cmdstr};
        }
        //执行命令
        Process process = Runtime.getRuntime().exec(cmdarray);
        if (isNeedReturn) {
            //获取结果流
            InputStream fis = process.getInputStream();
            //读取结果流
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
            String line = null;
            while ((line = br.readLine()) != null) {
                if (line.trim().length() != 0) {
                    lineList.add(line);
                }
            }
            return lineList;
        }
        return null;
    }

本文标题:根据命令执行
本文路径:http://lszwz.com/article/jsjdpp.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款