Java.io.Exception: Working Directory: null Environment: null



我正在尝试从我的应用程序目录运行 shell 命令,但得到"工作目录空和环境空"。

我在这里看了几篇帖子,但我不太确定从这里开始。

错误:运行 exec(( 时出错。命令: [/data/user/0/com.netscout.iperf3_clientls] 工作目录: 空 环境: 空

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

尝试为要从中运行的脚本设置工作目录。另外,我建议使用ProcessBuilder来完成您的工作:

https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html

最新更新