cordova应用程序执行bash的权限

时间:2017-06-24 14:29:38

标签: android bash cordova

我有这样的插件代码:

"'ls --color=always'"

我现在正在尝试运行命令java.io.IOException: Permission denied 我引用命令。但是有例外:

{{1}}

如何在Android cordova应用程序上执行bash?我需要root才能运行bash吗?

1 个答案:

答案 0 :(得分: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;
}