Hi I'm trying to execute shell commands from an app. Though the code runs with out any error, the output is not seen. As an example I'm trying to copy a file. This command works fine, while executing via shell command prompt. Here is the code I used..From the debug statements in LogCat, I could know all the code blocks are covered. But the file is not copied. Kindly suggest a solution. PS: I'm running this via emulator..
@Override
public void onClick(View v) {
if (v.getId() == R.id.click_button){
String[] commands = {"cp /mnt/sdcard/rr.txt /mnt/sdcard/zzzz.txt"};
try {
Log.d("Ac","before fun call.....");
RunAsRoot(commands);
Log.d("Ac","after fun call...");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void RunAsRoot(String[] cmds) throws IOException{
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
for (String tmpCmd : cmds) {
os.writeBytes(tmpCmd+"\n");
Log.d("Ac","inside...");
}
os.writeBytes("exit\n");
Log.d("Ac","outsidee...");
os.flush();
}
}