运行exec()时出错。命令

时间:2016-06-16 18:46:41

标签: android process processbuilder pptp

我尝试从Github Sample连接PPTP VPN。

但是发生了一些错误:

    Error running exec(). Command: [su] Working Directory: null Environment: [ANDROID_ROOT=/system, BOOTCLASSPATH_EX=/system/framework/mediatek-op.jar, EMULATED_STORAGE_SOURCE=/mnt/shell/emulated, USBOTG_STORAGE=/storage/usbotg, LOOP_MOUNTPOINT=/mnt/obb, EMULATED_STORAGE_TARGET=/storage/emulated, ANDROID_BOOTLOGO=1, LD_LIBRARY_PATH=/vendor/lib:/system/lib, EXTERNAL_STORAGE=/storage/emulated/legacy, ANDROID_SOCKET_zygote=9, ANDROID_DATA=/data, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ANDROID_ASSETS=/system/app, ASEC_MOUNTPOINT=/mnt/asec, BOOTCLASSPATH=/system/framework/core.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/framework2.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/webviewchromium.jar:/system/framework/mediatek-common.jar:/system/framework/mediatek-framework.jar:/system/framework/CustomProperties.jar:/system/framework/mediatek-telephony-common.jar:/system/framework/mediatek-tablet.jar:/system/framework/com.htc.android.home.clock.jar:/system/framework/cei-wrapper.jar, ANDROID_PROPERTY_WORKSPACE=8,0, ANDROID_STORAGE=/storage]
             java.io.IOException: Error running exec(). Command: [su] Working Directory: null Environment: [ANDROID_ROOT=/system, BOOTCLASSPATH_EX=/system/framework/mediatek-op.jar, EMULATED_STORAGE_SOURCE=/mnt/shell/emulated, USBOTG_STORAGE=/storage/usbotg, LOOP_MOUNTPOINT=/mnt/obb, EMULATED_STORAGE_TARGET=/storage/emulated, ANDROID_BOOTLOGO=1, LD_LIBRARY_PATH=/vendor/lib:/system/lib, EXTERNAL_STORAGE=/storage/emulated/legacy, ANDROID_SOCKET_zygote=9, ANDROID_DATA=/data, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ANDROID_ASSETS=/system/app, ASEC_MOUNTPOINT=/mnt/asec, BOOTCLASSPATH=/system/framework/core.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/framework2.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/webviewchromium.jar:/system/framework/mediatek-common.jar:/system/framework/mediatek-framework.jar:/system/framework/CustomProperties.jar:/system/framework/mediatek-telephony-common.jar:/system/framework/mediatek-tablet.jar:/system/framework/com.htc.android.home.clock.jar:/system/framework/cei-wrapper.jar, ANDROID_PROPERTY_WORKSPACE=8,0, ANDROID_STORAGE=/storage]
                 at java.lang.ProcessManager.exec(ProcessManager.java:211)
                 at java.lang.ProcessBuilder.start(ProcessBuilder.java:195)
                 at mycompany.lightvpn.util.RunCommand.run(RunCommand.java:26)
                 at mycompany.lightvpn.manager.VpnManager.startMtpd(VpnManager.java:128)
                 at mycompany.lightvpn.manager.VpnManager.startVpn(VpnManager.java:32)
                 at mycompany.lightvpn.MainActivity$6.run(MainActivity.java:248)
                 at java.lang.Thread.run(Thread.java:841)
              Caused by: java.io.IOException: Permission denied
                 at java.lang.ProcessManager.exec(Native Method)
                 at java.lang.ProcessManager.exec(ProcessManager.java:209)
                 at java.lang.ProcessBuilder.start(ProcessBuilder.java:195) 
                 at mycompany.lightvpn.util.RunCommand.run(RunCommand.java:26) 
                 at mycompany.lightvpn.manager.VpnManager.startMtpd(VpnManager.java:128) 
                 at mycompany.lightvpn.manager.VpnManager.startVpn(VpnManager.java:32) 
                 at mycompany.lightvpn.MainActivity$6.run(MainActivity.java:248) 
                 at java.lang.Thread.run(Thread.java:841)

方法:

    public static Process run(String command) throws IOException {
        LTH.dLog("GET_VPN", "Run Command -> Run -> Command : " + command);
        /*String DIR_SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath();
        String DIR_APP = DIR_SDCARD + "/Android/data/" + context.getPackageName() + "/dir/";*/
        /*List<String> strings = new ArrayList<>();
        strings.add("su");
        strings.add("-c");
        strings.add(command);
        ProcessBuilder builder = new ProcessBuilder(strings);*/
        // ProcessBuilder builder = new ProcessBuilder("su");
        ProcessBuilder builder = new ProcessBuilder("su");
                /*.command(command)
                .redirectErrorStream(true);*/
        // Process p = Runtime.getRuntime().exec("su");
        Process p = builder.start(); // Error Line
        DataOutputStream dos = new DataOutputStream(p.getOutputStream());

        dos.writeBytes(command + "\n");
        dos.flush();
        dos.writeBytes("exit\n");
        dos.flush();
        return p;
    }

我如何修复它?

0 个答案:

没有答案