[英]libsuperuser get command output in real time
我從未使用過libsuperuser,而僅使用過roottools。 現在,我想切換到libsuperuser,但是我沒有找到一種方法來以root身份調用命令並讀取命令的輸出,而無需等待命令完成。 使用roottools很容易,因為它有一個方法,該方法每次在進程將新行寫入stdout時都被調用。 但是對於libsuperuser,我僅找到Shell.SU.run()
返回該輸出,但僅在該過程完成時才返回輸出。 如何使用libsuperuser實時讀取輸出行?
您必須使用Shell.Interactive.addCommand()
及其回調:
Shell.Interactive rootSession = new Shell.Builder().useSU().open(/*...*/);
會話打開后,您可以添加命令:
rootSession.addCommand(new String[] { "ls -l /sdcard" },
1, // a command id
new Shell.OnCommandLineListener() {
@Override
public void onCommandResult(int commandCode, int exitCode) {
// ...
}
@Override
public void onLine(String line) {
// ...
}
});
您正在尋找onLine(String line)
。
請參閱Chainfire的libsuperuser存儲庫中的示例代碼“ InteractiveActivity” 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.