I have the following method for running shell commands in my java applications and i’m looking to run a few scripts such as one that fixes permissions for all applications on the users phone. I can run the script no problem by using this command execCommand(“/system/xbin/fix_perm”); however the problem is that i want to just print out what’s being done like terminal emulator does how can i take my outputstream and print it on the screen? Thank you for any help
public Boolean execCommand(String command)
{
try {
Runtime rt = Runtime.getRuntime();
Process process = rt.exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command + "\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (IOException e) {
return false;
} catch (InterruptedException e) {
return false;
}
return true;
}
I’m hoping you’re aware of the potentially extreme consequences of allowing a user to run arbitrary commands as
suand will instead point to a possible solution.