如何从android应用程序运行.sh文件?
我的设备已根目录,现在我想从android应用程序运行一个如何从android应用程序运行.sh文件?,android,adb,adb-shell,Android,Adb,Adb Shell,我的设备已根目录,现在我想从android应用程序运行一个.sh文件。我尝试了以下代码,但没有提供预期的输出: Process process = Runtime.getRuntime().exec("sh /data/local/tmp/xyz.sh"); 如果我从adb运行.sh文件,它对我来说工作正常。尝试以下代码 Process process = Runtime.getRuntime().exec("sh /data/local/tmp/xyz.sh"); Scanner stdou
.sh
文件。我尝试了以下代码,但没有提供预期的输出:
Process process = Runtime.getRuntime().exec("sh /data/local/tmp/xyz.sh");
如果我从adb运行.sh
文件,它对我来说工作正常。尝试以下代码
Process process = Runtime.getRuntime().exec("sh /data/local/tmp/xyz.sh");
Scanner stdout = new Scanner(process.getInputStream());
while (stdout.hasNextLine()) {
Log.i("stdout", stdout.nextLine());
}
stdout.close();
Scanner stderr = new Scanner(process.getErrorStream());
while (stderr.hasNextLine()) {
Log.e("stderr", stderr.nextLine());
}
stderr.close();
try{
Process root = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(root.getOutputStream());
os.writeBytes("sh /system/bin/xyz.sh \n");
os.flush();
}
catch (IOException e) {
e.printStackTrace();
}
catch (SecurityException se){
se.printStackTrace();
}
这段代码对我很有用,希望能对您有所帮助。谢谢您的回复,但这段代码也没用!:-(@Newbie what不起作用?您需要更具体地说,..sh文件没有被执行。语法和拼写编辑,但作者必须添加更多关于预期内容和错误输出的详细信息