在某些Android设备,在亚洲开发银行的外壳,我只能跑echo
,cd
,ls
.当我跑:
tar -cvf //mnt/sdcard/BackUp1669/apk/test.tar /mnt/sdcard/test.apk
Run Code Online (Sandbox Code Playgroud)
或者命令cp
,它返回:
sh: tar: not found
Run Code Online (Sandbox Code Playgroud)
为什么我不能运行这些命令?某些设备支持这些命令.我的最终目标是将文件从/ data/data文件夹复制到SD卡.我得到了su,我得到了以下代码:
int timeout = 1000;
String command = "tar -cvf /" + Environment.getExternalStorageDirectory() + "/cp/"
+ packageName + ".tar" + " " + path;
DataOutputStream os = new DataOutputStream(process.getOutputStream());
BufferedReader is = new BufferedReader(new InputStreamReader(new DataInputStream(
process.getInputStream())), 64);
String inLine;
try {
StringBuilder sbCommand = new StringBuilder();
sbCommand.append(command).append(" ");
sbCommand.append("\n");
os.writeBytes(command.toString());
if (is != null) {
for (int i = 0; i < timeout; i++) {
if (is.ready())
break;
try {
Thread.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (is.ready()) {
inLine = is.readLine();
} else {
}
}
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
它总是停在里面is.ready()
,当我改变它时process.waitfor()
它也停了下来.为什么?
waq*_*lam 10
据我所知,运行shell命令的唯一方法是:
Process proc = Runtime.getRuntime().exec("your command");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
39526 次 |
最近记录: |