プロジェクトのアセットフォルダーに保存されているbusyboxバイナリライブラリを使用するアプリをコーディングしています。実行時に、このライブラリをフォルダにコピーし/data/data/com.myapp/
、このファイルを実行可能にしてから、このバイナリライブラリから利用できるはずのいくつかのutilcmdを実行しようとします。しかし、私は望ましい結果を得ていません。次の関数を使用します:
private void shellCmd()
{
try {
Process process = null;
/* I used this to make the file executable */
// process = Runtime.getRuntime().exec("/system/bin/chmod 777 "
// + this.getFilesDir().getPath() + "/busybox");
// process = Runtime.getRuntime().exec("/system/bin/ls -l "
// + this.getFilesDir().getPath() + "/busybox");
/* this exec function doesnt execute(there is no prompt into logcat)*/
process = Runtime.getRuntime().exec( this.getFilesDir().getPath() + "/busybox ping -4 46.173.103.134");
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
Log.w("groupAB",output.toString());
Log.i("groupAB", "finish");
process.waitFor();
return;
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
しかし、adbを使用して同じcmdを実行しようとすると、"adb shell /data/data/com.myapp/busybox ping -4 46.173.103.134"
正しいping結果が得られます。なぜこれがプログラミングの方法で機能しないのか混乱しています。私のせいはどこですか?