java代码执行cmd你会不,用Runtime类或Process类

解决方案 »

  1.   

    Process ps=Runtime.getRuntime().exec("su");
    如何获取其输出
      

  2.   

    Process ps=Runtime.getRuntime().exec("ls");
    byte[] b=new byte[50];
    ps.getErrorStream().read(b,0,50);     
        String test=new String(b,0,50);
        ps.waitFor();     
        if( test.indexOf("su")>=0){
         isroot="not root";
        }
        else{
         isroot="is root";
        }

    如果非root运行正常,如果是root程序就卡死了死机了
      

  3.   

    Process ps=Runtime.getRuntime().exec("su");
    byte[] b=new byte[50];
    ps.getErrorStream().read(b,0,50);    
    String test=new String(b,0,50);
    ps.waitFor();    
    if( test.indexOf("su")>=0){
    isroot="not root";
    }
    else{
    isroot="is root";
    }如果非root运行正常,如果是root程序就卡死了死机了
      

  4.   


    我晕晕晕
    ,我只想判断一下是不是root弄的程序那么复杂
      

  5.   


        process = Runtime.getRuntime().exec("su");
        process.waitFor();
        i = process.exitValue();
        根据i的值判断是否是root权限
      

  6.   

    java代码貌似没有root执行的,最多也就是system
      

  7.   

    自己找到答案了
    File su = new File("/system/bin/su");
    if (su.exists()