내 장치에서 rsync를 실행하려고합니다. /system/xbin/rsync
에 바이너리가 있는데 나는 Runtime.getRuntime().exec
으로 시작하려고합니다. 나는 안드로이드 프로그래밍에 익숙하지 않기 때문에 수퍼 유저 권한을 사용자에게 부여해야한다면 아직 얻지 못한다.Android Runtime.getRuntime(). exec 및 rsync
내 코드는 다음과 같습니다
try {
Process process = Runtime.getRuntime().exec(
"/system/xbin/rsync -avzru /sdcard/Tinybox/ " +
"[email protected]::88124bb378ac994088e704d553de6f19");
System.out.print("RSYNC LAUNCHED\n");
// Reads stdout.
// NOTE: You can write to stdin of the command using
// process.getOutputStream().
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();
// Waits for the command to finish.
process.waitFor();
System.out.print(output);
System.out.print("RSYNC FINISHED\n");
// return output.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
그리고 그것은 작동하지 않습니다, 그냥 "RSYNC 완료" "RSYNC가 시작"인쇄합니다.
하지만 실행하는 경우 : 잘 작동
Process process = Runtime.getRuntime().exec("/system/xbin/rsync --help");
, 나는 로그 캣 창에서 출력을 볼 수 있습니다.
try {
System.out.print("RSYNC STARTED\n");
Process process = Runtime.getRuntime().exec("/system/xbin/su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
DataInputStream is = new DataInputStream(process.getInputStream());
os.writeBytes("/system/xbin/rsync --help");
String output = new String();
String temp = new String();
output = is.readLine();
System.out.print(output);
os.flush();
System.out.print("RSYNC FINISHED\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
}
을하지만 코드를 실행할 때 응용 프로그램이 오류없이 정지 :
그래서 나는 슈퍼 유저 권한을 사용할 필요가 다음과 같이 내가 내 코드를 수정 같아요.
'오류없이 정지되었습니다. 'LogCat이없는 것이 확실합니까? – Budius
아무것도, RSYNC STARTED와 그 이상을 인쇄하지 않습니다. – phcaze
기기가 뿌리를 내 립고 있습니까? –