如何在 Runtime.getRuntime().exec() android 中正确运行 iperf 命令



我尝试在我的安卓设备中运行 iperf 服务器和客户端,所以我使用 exec() 开发了一个应用程序,它适用于 ls、ping 等命令,但是当我尝试运行 iperf -s 时,我遇到了错误,这是代码,我在清单文件中添加了互联网权限。帮助将不胜感激

iperf 命令的工作目录和环境是什么?

        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");
            }
        } 

我收到以下错误

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

听起来有权限问题,请检查您的日志猫行:

Caused by: java.io.IOException: Permission denied

也许您可以尝试在外部SD卡中执行二进制iperf? 尝试添加读/写外部存储的权限。

相关内容

  • 没有找到相关文章

最新更新