2017-06-24 4 views

答えて

0

それはbashがデバイス上に存在しないと思われるファイルが見つからないとき、それは許可エラーをスローし、このコードは動作します:

public String exec(String command) throws IOException, InterruptedException { 
    Process bash = Runtime.getRuntime().exec("sh"); 
    DataOutputStream outputStream = new DataOutputStream(bash.getOutputStream()); 
    outputStream.writeBytes(command + "\n"); 
    outputStream.flush(); 
    outputStream.writeBytes("exit\n"); 
    outputStream.flush(); 
    InputStreamReader is = new InputStreamReader(bash.getInputStream()); 
    BufferedReader reader = new BufferedReader(is); 
    bash.waitFor(); 
    String output = TextUtils.join("\n", this.read(reader)); 
    return output; 
} 
関連する問題