【发布时间】:2018-03-08 19:52:45
【问题描述】:
我正在尝试从我的应用程序目录运行 shell 命令,但我得到“工作目录为空且环境为空。
我在这里查看了几篇帖子,但我不太确定从这里去哪里。
错误: 运行 exec() 时出错。命令:[/data/user/0/com.netscout.iperf3_clientls] 工作目录:null 环境:null
public void startApp() {
StringBuffer output = new StringBuffer();
Process process = null;
String appFileDir = getApplicationInfo().dataDir;
// String commandLine = appFileDir + "/iperf3 -c 129.196.197.116 --forceflush -O3 -Z -P2";
String commandLine = appFileDir + "ls";
try {
process = Runtime.getRuntime().exec(commandLine, null, null);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
// output.append(line + "/n");
Log.e("Line", String.valueOf(line));
Log.e("output", String.valueOf(output));
}
} catch (IOException e) {
e.printStackTrace();
Log.i("Output", String.valueOf(e));
}
}
【问题讨论】:
标签: java android android-studio mobile-development