Android 장치에서 프로그래밍 방식으로 일부 셸 명령을 실행하려고합니다. 일부 명령을 실행할 수는 있지만 모든 명령을 실행하지 못했습니다.Android Studio의 ADB 셸에서 명령 실행
executeCommandLine(“ls”)
executeCommandLine(“netstat –atun”)
하지만 지금은 제대로 실행되지 않습니다 다음 명령을 실행해야합니다 :
$ adb push netstat3 /data/local/tmp/
$ adb shell
$ chmod 755 /data/local/tmp/netstat3
$ /data/local/tmp/netstat3
나는 위를 실행하는 기능을 썼다을 예를 들어 나는 다음과 같은 명령을 실행 할 수 있어요 Android에서 언급 된 명령. 이 함수는 "ls"및 "netstat -atun"과 같은 명령에 대한 올바른 출력을 제공하지만 다음 명령에 대한 올바른 응답을 제공하지 않습니다. 나는 나의 모든 명령에 대한 응답을받을 수있는 방법을 알고 싶습니다
public String executeCommandLine(String commandLine) {
try {
Process process;
process = Runtime.getRuntime().exec(commandLine);
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String read;
StringBuilder output=new StringBuilder();
while ((read = reader.readLine())!=null){
output.append(read);
output.append("\n");
Log.d("executed command ", output.toString());
}
reader.close();
process.waitFor();
return output.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
: 내 executeCommandLine 기능은 다음과 같다.
내가 잘못하지 않았다면, 응용 프로그램 내에서 Android 폰에서 프로그래밍 방식으로 명령을 실행하고 싶다고 말할 수 있습니까? –
예 내 응용 프로그램 내에서 Android 휴대 전화에서 프로그래밍 방식으로 실행하고 싶습니다. – Bouba
앱에서'adb push'를 실행하려고합니까? –