본문 바로가기

안드로이드/ADB & Rooting

[Android] 소스에서 Shell Command, Script 실행하는 법

 Runtime runtime = Runtime.getRuntime();
        try{
         Process p = runtime.exec("명령어");
         BufferedReader br 
= new BufferedReader(new InputStreamReader(p.getInputStream()));
         String line = null;
         while ((line = br.readLine())!=null){
         Log.d("Test",line);
         }
         br.close();
        
        }catch(Exception e){
         Log.d("Test",e.toString());
        }



쉘스크립트를 실행시켜야 할때, 

int i;

try{

Process ps = Runtime.getRuntime().exec(command);

ps.waitFor();

       System.out.println(ps.exitValue());

        ps.destroy();

}catch(Exception e){

       e.printStackTrace();

}