在某些 Android 设备上,在 ADB shell 中,我只能运行echo
, cd
, ls
. 当我运行时:
tar -cvf //mnt/sdcard/BackUp1669/apk/test.tar /mnt/sdcard/test.apk
或命令cp
,它返回:
sh: tar: not found
为什么我不能运行这些命令?一些设备支持这些命令。我的最终目标是将文件从/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();
}
它总是停在is.ready()
,当我把它改成它时,process.waitfor()
它也停了。为什么?