Get the output from executed commands through android app Code Answer

I’m performing the following code to execute linux commands in my android application that I’m creating:

public void RunAsRoot(String[] cmds){
            Process p = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(p.getOutputStream());            
            for (String tmpCmd : cmds) {

I want to know if there is a way to know what the command is returning after it is executing. for example, if I do “ls” I would like to see what the command wold normally output.


try this code :

try {
  Process process = Runtime.getRuntime().exec("ls");
  BufferedReader bufferedReader = new BufferedReader(
  new InputStreamReader(process.getInputStream()));

  StringBuilder result=new StringBuilder();
  String line = "";
  while ((line = bufferedReader.readLine()) != null) {
  TextView tv = (TextView)findViewById(;
catch (IOException e) {}

Related Posts

© No Copyrights, All Questions are retrived from public domain.
Tutorial Guruji