Android: Problem starting the program from the shell

DustOfRust 141 Reputation points
2021-04-23T13:23:50.64+00:00

Tries to run the "/ data / local / tmp / iperf" program from the android application. unfortunately the program returns a "no permissions" error.

  Java.Lang.Process processa = Java.Lang.Runtime.GetRuntime().Exec("/data/local/tmp/iperf -v");
                Java.IO.BufferedReader inas = new Java.IO.BufferedReader(new Java.IO.InputStreamReader(processa.InputStream));

                using (var outputStreamReader = new StreamReader(processa.InputStream))
                {
                    textMessage.Text = await outputStreamReader.ReadToEndAsync();
                }

****Error: Java.IO.IOException: 'Cannot run program "/data/local/tmp/iperf": error=13, Permission denied'****

Running from adb shell works

adb shell /data/local/tmp/iperf -v
iperf version 2.0.5 (08 Jul 2010) pthreads

How to run such an Android application correctly?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,337 questions
{count} votes

Accepted answer
  1. DustOfRust 141 Reputation points
    2021-04-26T13:51:13.07+00:00

    I find solution, API29+ have more "feature": Removed execute permission for app home directory

    The workaround is to rename the executable from "iperf" to "libiperf.so", and create "lib" directory, make "arm64-v8a" subdirectory and put "libiperf.so" there.

    Then you can execute iperf

    91308-iperf.png

    Java.Lang.Process processIperf = Java.Lang.Runtime.GetRuntime().Exec(ApplicationInfo.NativeLibraryDir + "/libiperf.so -v");  
      
    Java.IO.BufferedReader bufferedReader = new Java.IO.BufferedReader(new Java.IO.InputStreamReader(processIperf.InputStream));  
    

    For more details and discussions, please go to the internet. No decent solution, there are only more workarounds;)

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.