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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -