0

I try to run python application on Android in my application.
This script work correct in Better Terminal Emulator Pro

su
busybox chroot /data/local/debian /bin/bash
/usr/bin/python /usr/src/script.py

Then I enter value

>>value1
result

But if I tried it in my app that:

String line;
Runtime.getRuntime().exec("su");
Runtime.getRuntime().exec("busybox chroot /data/local/debpsla /bin/bash");
Process proc = Runtime.getRuntime().exec("ls");
OutputStreamWriter osw = new OutputStreamWriter(proc.getOutputStream());

proc.waitFor();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
while ((line = bufferedReader.readLine()) != null){ 
   publishProgress(line); 
}

Command ls return not right list of files. This means that root directory don't changed.
What I do incorrect?
Thanks!

1 Answers1

0

You are running each command separately as they start a new process each and with only the JVM's context. This means you are running su and busybox chroot /data/local/debpsla /bin/bash and ls as concurrent and unrelated processes.

If you want one to follow the other you have do this all in one process. I suspect writing a script which you execute will be easier.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • 1
    I think your answer may not be clear that each call to exec starts a new process and is therefore unrelated to the previous call. – Zagrev Mar 09 '13 at 20:40
  • I tried this http://stackoverflow.com/a/3350862/2143772 example. But also chroot didn't work. – Ilya Moroseiko Mar 10 '13 at 10:31