0
パラメータ(空白を含んでいますか?!)でsuを実行すると問題が発生しました。私のCommand.javaは次のようになります:Androidルートはパラメータでsuを実行します
public class Command
{
Process process;
public String executeCommand(String command)
{
StringBuffer output = new StringBuffer();
try {
process = Runtime.getRuntime().exec(command);
process.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
String response = output.toString();
return response;
}
}
私のMainActivityでは、単一コマンドで動作しています。それが動作していることを
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView content = (TextView) findViewById(R.id.txt_content);
Command cmd = new Command();
String outp = cmd.executeCommand("su -c 'id'");
Log.d("OOOOOOUT", outp);
content.setText(outp);
}
結果を示し、:
D/OOOOOOUT: uid=0(root) gid=0(root) context=u:r:init:s0
これはまた、lsコマンドのために働いています。しかし、私がパラメターと引数を解析しようとすると、実行されません。
など。
String outp = cmd.executeCommand("su -c 'ls /data/data/'");
Log.d("OOOOOOUT", outp);
content.setText(outp);
私はまた、次のことをしようと試み:
String outp = cmd.executeCommand("su -c \'ls /data/data/\'");
String outp = cmd.executeCommand("su -c 'ls -l'");
、さらに。私は、シェル内でこのコマンドを実行すると、直接私は、次のような出力を得る:アプリケーション内でも
[email protected]:/ $ /system/xbin/su -c 'ls -l'
drwxr-xr-x root root 1970-06-20 18:01 acct
drwxrwx--- system cache 2016-06-21 22:06 cache
:
[email protected]:/ $ su -c 'ls -l'
drwxr-xr-x root root 1970-06-20 18:01 acct
drwxrwx--- system cache 2016-06-21 22:06 cache
-rwxr-x--- root root 272364 1970-01-01 01:00 charger
dr-x------ root root 1970-06-20 18:01 config
を私はまた、完全なパスを使用しようと試みました。私はその解析エラーを推測します。時には、コマンドの最後に "\ n"を追加している人がいますか?なぜか言わない。私はこのトピックの中でどんな助けにも本当に感謝しています。ありがとう!
ありがとうございました!これは動作しています:) – user3325230