2013-03-09 166 views
0

我試着在我的應用程序上運行Android上的python應用程序。
這個腳本工作正確的更好的終端模擬器臨Runtime.getRuntime().exec()工作不正確

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

然後我輸入值

>>value1 
result 

但是,如果我試圖在我的應用程序是:

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); 
} 

命令ls返回不正確的文件列表。這意味着根目錄不會更改。
我做錯了什麼?
謝謝!

回答

0

您正在分別運行每個命令,因爲它們各自啓動一個新進程並且僅使用JVM的上下文。這意味着您正在運行subusybox chroot /data/local/debpsla /bin/bashls作爲併發和不相關的進程。

如果你想跟隨另一個,你可以在一個過程中做到這一切。我懷疑寫一個你執行的腳本會更容易。

+1

我認爲你的答案可能並不清楚每次調用exec都會啓動一個新進程,因此與之前的調用無關。 – Zagrev 2013-03-09 20:40:16

+0

我試過這個http://stackoverflow.com/a/3350862/2143772例子。但是chroot也沒有工作。 – 2013-03-10 10:31:10

相關問題