Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Android应用程序执行脚本_Android_Shell - Fatal编程技术网

通过Android应用程序执行脚本

通过Android应用程序执行脚本,android,shell,Android,Shell,我有一个安卓应用程序,我已经安装为一个系统应用程序(in/system/app),它意味着执行一个shell脚本,传递一些用户在应用程序中设置的变量。 我使用的代码是: public void onClick(View v) { try{ Log.i("MyActivity", "trying"); Process su = Runti

我有一个安卓应用程序,我已经安装为一个系统应用程序(in/system/app),它意味着执行一个shell脚本,传递一些用户在应用程序中设置的变量。 我使用的代码是:

public void onClick(View v) {

                        try{
                            Log.i("MyActivity", "trying");
                            Process su = Runtime.getRuntime().exec("su");
                            DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

                            outputStream.writeBytes("busybox chroot /uoa /bin/createuser.sh " + username.getText().toString() + " " + password.getText().toString());
                            outputStream.flush();

                            outputStream.writeBytes("exit\n");
                            outputStream.flush();
                            su.waitFor();
                        }catch(IOException e){
                            Log.e("MyActivity", e.toString());
                        }catch(InterruptedException e){
                            Log.e("MyActivity", e.toString());
                        }
            } 
但是,我得到一个错误:

E/MyActivity(1872):java.io.IOException:写入失败:EPIPE(断开) (管道)

并且脚本不会被执行。我知道该脚本可以工作,因为我可以通过adb shell运行该命令

busybox chroot/uoa/bin/createuser.sh testuser测试

还有,如何从脚本中获取要记录的输出