0

これが私が作ろうとしているものの例です:

final String[] hwdebug1 = {"su","-c","echo hello > /system/hello1.txt"};

                 try {
                     Runtime.getRuntime().exec(hwdebug1);              
                } catch (IOException e) {
                }            

したがって、ボタンをクリックすると完全に機能しますが、たとえば、次のようなことをすると機能しません。

final String[] hwdebug1 = {"su","-c","echo hello > /system/hello1.txt","echo hello > /system/hello2.txt","echo hello > /system/hello3.txt"};

私の意図は、ボタンに複数のコマンドを実行させることです。私はすでにbashスクリプトを実行させることでそれを実行しましたが、コードに配置する方法を見つけることを好みます。

ありがとう!

Ben75メソッドで解決

final String[] hwdebug1 = {"su","-c","echo hello > /system/hello1.txt"};
final String[] hwdebug2 = {"su","-c","echo hello > /system/hello2.txt"};
final String[] hwdebug3 = {"su","-c","echo hello > /system/hello3.txt"};
ArrayList<String[]> cmds = new ArrayList<String[]>();
cmds.add(hwdebug1);
cmds.add(hwdebug2);
cmds.add(hwdebug3);
for(String[] cmd:cmds){
    try {
       Runtime.getRuntime().exec(cmd);              
   } catch (IOException e) {
       e.printStacktrace(); 
   }          
}
4

1 に答える 1

2

Runtime.execコマンドは、1つのコマンドに対して機能し、コマンド行文字列の単純な「ラッパー」ではありません。

リストを作成して繰り返します。

final String[] hwdebug1 = {"su","-c","echo hello > /system/hello1.txt"};
final String[] hwdebug2 = {"su","-c","echo hello > /system/hello2.txt"};
final String[] hwdebug3 = {"su","-c","echo hello > /system/hello3.txt"};
ArrayList<String[]> cmds = new ArrayList<String[]>();
cmds.add(hwdebug1);
cmds.add(hwdebug2);
cmds.add(hwdebug3);
for(String[] cmd:cmds){
    try {
       Runtime.getRuntime().exec(cmd);              
   } catch (IOException e) {
       e.printStacktrace(); 
   }          
}
于 2013-01-24T09:54:38.797 に答える