简体   繁体   中英

How to run iperf command properly in Runtime.getRuntime().exec() android

I try to run iperf server and client in my android device so i develop an app using exec() and it is working fine for ls, ping etc. command but when i try to run iperf -s i got error, Here is the code and i added internet permission in manifest file. Help will appreciate

What will be the working directory and environment for iperf command??

        StringBuffer output = new StringBuffer();

        Process p;
        try {
            p = Runtime.getRuntime().exec(command);
            p.waitFor();
            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

            String line = "";           
            while ((line = reader.readLine())!= null) {
                output.append(line + "\n");
            }

        } 

I got following Error

06-14 13:14:01.023: W/System.err(1465): java.io.IOException: Error     running exec(). Command: [iperf, -s] Working Directory: null Environment: null
06-14 13:14:01.033: W/System.err(1465):     at java.lang.ProcessManager.exec(ProcessManager.java:211)
06-14 13:14:01.033: W/System.err(1465):     at   java.lang.Runtime.exec(Runtime.java:173)
06-14 13:14:01.053: W/System.err(1465):     at java.lang.Runtime.exec(Runtime.java:246)
06-14 13:14:01.053: W/System.err(1465):     at java.lang.Runtime.exec(Runtime.java:189)
06-14 13:14:01.053: W/System.err(1465):     at com.learn2crack.androidshell.ShellExecuter.Executer(ShellExecuter.java:20)
06-14 13:14:01.053: W/System.err(1465):     at com.learn2crack.androidshell.MainActivity$1.onClick(MainActivity.java:33)
06-14 13:14:01.063: W/System.err(1465):     at android.view.View.performClick(View.java:4438)
06-14 13:14:01.063: W/System.err(1465):     at android.view.View$PerformClick.run(View.java:18422)
06-14 13:14:01.063: W/System.err(1465):     at android.os.Handler.handleCallback(Handler.java:733)
06-14 13:14:01.063: W/System.err(1465):     at android.os.Handler.dispatchMessage(Handler.java:95) 
06-14 13:14:01.063: W/System.err(1465):     at android.os.Looper.loop(Looper.java:136)
06-14 13:14:01.073: W/System.err(1465):     at android.app.ActivityThread.main(ActivityThread.java:5017)
06-14 13:14:01.073: W/System.err(1465):     at java.lang.reflect.Method.invokeNative(Native Method)
06-14 13:14:01.073: W/System.err(1465):     at java.lang.reflect.Method.invoke(Method.java:515)
06-14 13:14:01.083: W/System.err(1465):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-14 13:14:01.083: W/System.err(1465):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-14 13:14:01.103: W/System.err(1465):     at dalvik.system.NativeStart.main(Native Method)
06-14 13:14:01.113: W/System.err(1465): Caused by: java.io.IOException: Permission denied
06-14 13:14:01.113: W/System.err(1465):     at java.lang.ProcessManager.exec(Native Method)
06-14 13:14:01.113: W/System.err(1465):     at java.lang.ProcessManager.exec(ProcessManager.java:209)
06-14 13:14:01.123: W/System.err(1465):     ... 16 more

Sound a permissions problem check your logcat line:

Caused by: java.io.IOException: Permission denied

Maybe you can try execute a binary iperf in a external sd card? try to add permissions to read/write external storage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM