document.write("");

Android 使用CMD命令

已知,Android是Linux系统,

在执行Linux 命令之前,需要 chmod 777 ,否则会报 权限拒绝,如下是执行命令   netstat -ntu | grep tcp | awk '{print $5}   时的写法

 

    public static void execR() {
        try {
            String command = "chmod 777";
            Runtime runtime = Runtime.getRuntime();
            Process proc = runtime.exec(command);
            Process proc1 = runtime.exec("netstat -ntu | grep tcp | awk '{print $5}'");
            InputStream inIs = null;
            inIs = proc1.getInputStream();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int read = -1;
            while ((read = inIs.read()) != -1) {
                baos.write(read);
            }
            byte[] data = baos.toByteArray();
            String result = new String(data);
            if (inIs != null) {
                inIs.close();
            }
            LogUtil.i("执行",result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

  

posted @ 2022-01-18 10:13  人间春风意  阅读(794)  评论(0)    收藏  举报