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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -