2013-01-14 6 views
3

내 장치에서 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 { 
} 

을하지만 코드를 실행할 때 응용 프로그램이 오류없이 정지 :

그래서 나는 슈퍼 유저 권한을 사용할 필요가 다음과 같이 내가 내 코드를 수정 같아요.

+0

'오류없이 정지되었습니다. 'LogCat이없는 것이 확실합니까? – Budius

+0

아무것도, RSYNC STARTED와 그 이상을 인쇄하지 않습니다. – phcaze

+0

기기가 뿌리를 내 립고 있습니까? –

답변

0

좋아, 나는 코드의 약간 다른 버전을 사용하고 있습니다 :

try { 
    System.out.print("RSYNC STARTED\n"); 
    process = Runtime.getRuntime().exec("/system/xbin/su -c sh"); 
    OutputStream os = process.getOutputStream(); 
    Log.d("RSYNC","/system/xbin/rsync" + " -avzru /sdcard/download/ [email protected]::TinyBox &"); 
    writeLine(os, "/system/xbin/rsync" + " -avzru /sdcard/download/ [email protected]::TinyBox &"); 

    os.flush(); 
    System.out.print("RSYNC FINISHED\n"); 
    } 
catch (IOException e) { 
    e.printStackTrace(); 
} 

나는 문제가 su 명령에 있다고 이해했다.

try { 
    System.out.print("RSYNC STARTED\n"); 
    process = Runtime.getRuntime().exec("sh"); 
    OutputStream os = process.getOutputStream(); 
    Log.d("RSYNC","/system/xbin/rsync" + " -avzru /sdcard/download/ [email protected]::TinyBox &"); 
    writeLine(os, "/system/xbin/rsync" + " -avzru /sdcard/download/ [email protected]::TinyBox &"); 

    os.flush(); 
    System.out.print("RSYNC FINISHED\n"); 
    } 
catch (IOException e) { 
    e.printStackTrace(); 
} 

를 잘 작동하지만, 내가 가지고 있기 때문에 물론 내가 rsync를에서 오류가 발생했습니다 : 내가 이전에 말했듯이 나는 su 명령을 제거하고 바로 시작할 경우, 오류 메시지와 함께 su 그 블록을 사용하여 rsync를 실행하는 경우 사용 권한이 없으며 동기화가 작동하지 않습니다. 내 문제를 어떻게 해결할 수 있을까 ??

+0

나는 그것을 풀었다! 마지막 코드가 잘 작동하는데, 잘못된 rsync 구성으로 인해 사용 권한 문제가 발생합니다! 감사 – phcaze

관련 문제