我尝试在我的Android设备中运行iperf服务器和客户端,所以我使用exec()开发应用程序,它正常工作ls,ping等命令,但当我尝试运行 iperf -s 我收到错误,这是代码,我在清单文件中添加了Internet权限。帮助将不胜感激
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
答案 0 :(得分:0)
声明权限问题检查您的logcat行:
Caused by: java.io.IOException: Permission denied
也许您可以尝试在外部SD卡中执行二进制 iperf ?尝试添加读/写外部存储的权限。