java - Get the output from executed commands through android app -


i'm performing following code execute linux commands in android application i'm creating:

public void runasroot(string[] cmds){             process p = runtime.getruntime().exec("su");             dataoutputstream os = new dataoutputstream(p.getoutputstream());                         (string tmpcmd : cmds) {                     os.writebytes(tmpcmd+"\n");             }                        os.writebytes("exit\n");               os.flush(); } 

i want know if there way know command returning after executing. example, if "ls" see command wold output.

try 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) {     result.append(line);   }   textview tv = (textview)findviewbyid(r.id.textview1);   tv.settext(result.tostring());   }  catch (ioexception e) {} 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -