RE :How can we execute a shell script file from my Android Application -
i trying write android application runs shell commands, or shell script if preferable, , displays output... can give me in right direction?
my code follows:
void execcommandline() { runtime runtime = runtime.getruntime(); process proc = null; outputstreamwriter osw = null; try { string[] str={"/system/bin/sh","/data/shtest.sh"}; system.out.println("exec string"); proc = runtime.exec(str); osw = new outputstreamwriter(proc.getoutputstream()); //osw.write(command); osw.flush(); osw.close(); } catch (ioexception ex) { log.e("erre","ioexception"); //log.e("execcommandline()", "command resulted in io exception: " + command); return; } { if (osw != null) { try { osw.close(); } catch (ioexception e){} } } try { proc.waitfor(); } catch (interruptedexception e){} if (proc.exitvalue() != 0) { log.e("erre","interruotexception"); //log.e("execcommandline()", "command returned error: " + command + "\n exit code: " + proc.exitvalue()); } } // **************************************
code running not getting output in adb shell logcat tell me if script executed how output in adb shell.
have looked gscript
. quite flexible.
Comments
Post a Comment