从android运行脚本获取java.io.IOException:权限被拒绝

时间:2018-07-12 02:58:06

标签: java android python android-permissions

public void dumpTrace()
{
    try{
        int number1 = 10;
        int number2 = 32;
        ProcessBuilder pb = new ProcessBuilder("python",
                "/home/cpu10475-local/Downloads/BlockTest/test1.py",
                ""+number1,
                ""+number2);
        Process p = pb.start();
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        int ret = Integer.parseInt(in.readLine());
       // System.out.println("value is : "+ret);
        Toast.makeText(context,"success",Toast.LENGTH_SHORT).show();
    }catch(Exception e){
        //Log.e("Exception","");
        Toast.makeText(context,"fail",Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
}

这是我用来运行python脚本的代码,该代码只接受两个整数并返回总和:

但是,从我的应用程序运行时,出现此错误:

07-12 09:36:54.380 1904-1904/com.example.cpu10475_local.blocktest W/System.err: java.io.IOException: Error running exec(). Command: [python, /home/cpu10475-local/Downloads/BlockTest/test1.py, 10, 32] Working Directory: null Environment: [ANDROID_ROOT=/system, ANDROID_BOOTLOGO=1, EXTERNAL_STORAGE=/sdcard, SYSTEMSERVERCLASSPATH=/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar, ANDROID_SOCKET_zygote=10, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ANDROID_DATA=/data, ANDROID_ASSETS=/system/app, ASEC_MOUNTPOINT=/mnt/asec, BOOTCLASSPATH=/system/framework/core-libart.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/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/apache-xml.jar:/system/framework/org.apache.http.legacy.boot.jar, ANDROID_PROPERTY_WORKSPACE=9,0, ANDROID_STORAGE=/storage]
07-12 09:36:54.381 1904-1904/com.example.cpu10475_local.blocktest W/System.err:     at java.lang.ProcessManager.exec(ProcessManager.java:211)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:195)
        at com.example.cpu10475_local.blocktest.TraceProcessing.dumpTrace(TraceProcessing.java:30)
        at com.example.cpu10475_local.blocktest.MainActivity$1.onClick(MainActivity.java:49)
        at android.view.View.performClick(View.java:5198)
        at android.view.View$PerformClick.run(View.java:21147)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    Caused by: java.io.IOException: Permission denied
        at java.lang.ProcessManager.exec(Native Method)
        at java.lang.ProcessManager.exec(ProcessManager.java:209)
        ... 12 more

我在模拟器上运行了它。

0 个答案:

没有答案