<legend id='y0ZEf'><style id='y0ZEf'><dir id='y0ZEf'><q id='y0ZEf'></q></dir></style></legend>

      <tfoot id='y0ZEf'></tfoot>
        <bdo id='y0ZEf'></bdo><ul id='y0ZEf'></ul>
    1. <i id='y0ZEf'><tr id='y0ZEf'><dt id='y0ZEf'><q id='y0ZEf'><span id='y0ZEf'><b id='y0ZEf'><form id='y0ZEf'><ins id='y0ZEf'></ins><ul id='y0ZEf'></ul><sub id='y0ZEf'></sub></form><legend id='y0ZEf'></legend><bdo id='y0ZEf'><pre id='y0ZEf'><center id='y0ZEf'></center></pre></bdo></b><th id='y0ZEf'></th></span></q></dt></tr></i><div id='y0ZEf'><tfoot id='y0ZEf'></tfoot><dl id='y0ZEf'><fieldset id='y0ZEf'></fieldset></dl></div>

      <small id='y0ZEf'></small><noframes id='y0ZEf'>

        设置 ProcessBuilder 的环境

        Setting the environment for ProcessBuilder(设置 ProcessBuilder 的环境)

        <i id='8VDEG'><tr id='8VDEG'><dt id='8VDEG'><q id='8VDEG'><span id='8VDEG'><b id='8VDEG'><form id='8VDEG'><ins id='8VDEG'></ins><ul id='8VDEG'></ul><sub id='8VDEG'></sub></form><legend id='8VDEG'></legend><bdo id='8VDEG'><pre id='8VDEG'><center id='8VDEG'></center></pre></bdo></b><th id='8VDEG'></th></span></q></dt></tr></i><div id='8VDEG'><tfoot id='8VDEG'></tfoot><dl id='8VDEG'><fieldset id='8VDEG'></fieldset></dl></div>
        <legend id='8VDEG'><style id='8VDEG'><dir id='8VDEG'><q id='8VDEG'></q></dir></style></legend>
          <tbody id='8VDEG'></tbody>

      1. <tfoot id='8VDEG'></tfoot>

                <small id='8VDEG'></small><noframes id='8VDEG'>

                  <bdo id='8VDEG'></bdo><ul id='8VDEG'></ul>
                  本文介绍了设置 ProcessBuilder 的环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I have a strange problem setting the Linux environment from Java (1.6); specifically the "PATH" variable.

                  In a nutshell, I have a pipeline for running native processes, which uses java.lang.ProcessBuilder. The user can optionally set the environment variables via a HashMap named environment:

                  ProcessBuilder pb = new ProcessBuilder(args);
                  Map<String, String> env = pb.environment();
                  if (environment != null)
                     env.putAll(environment);
                  Process process = pb.start();
                  

                  The env variable gets set properly, if I dump it to the console, with a correct value for the PATH variable. However, running the process results in a thrown Exception:

                  java.io.IOException: error=2, No such file or directory

                  The same process runs fine with identical environment variables in the terminal shell. To test this, I ran Eclipse AFTER setting the environment in the terminal. In this case the ProcessBuilder process runs correctly.

                  So what must be happening is that the ProcessBuilder is not using the environment I set for it, but the current System environment instead.

                  I can't find any satisfactory answers to this problem online. Perhaps this is an OS-specific issue? Or something else I'm missing?

                  解决方案

                  I don't think it's a bug, I think it's a problem with your understanding of the boundaries and roles of the environment variables at play. ProcessBuilder.environment() contains environment variables that will be "process-local" to the spawned process. They are not system-wide, or logon-wide, and they don't even affect the environment in which the ProcessBuilder is running.

                  The ProcessBuilder.environment() map contains process-local variables that will be seen only by the spawned process. Obviously a prerequisite to the spawned processing seeing the ProcessBuilder.environment() is successful spawning of the process, which is a point I do not think you're even getting to.

                  As far as I know, it's not really possible (from Java) to modify the currently-running process' PATH, which is what I think you're expecting to happen (or to be able to do.) So I think you must point ProcessBuilder to the fully qualified path to the executable you're trying to launch (or be certain that the PATH was set up correctly before you even launch the JVM that will use the ProcessBuilder, which is what you did in your 'working' scenario of setting it in the terminal before launching your IDE).

                  这篇关于设置 ProcessBuilder 的环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Maven JAVA_HOME environment variable is not defined correctly, but it is(Maven JAVA_HOME 环境变量未正确定义,但它是)
                  Java System Environment Variable(Java 系统环境变量)
                  Java -classpath option(Java -classpath 选项)
                  Read environment variable in SpringBoot(在 SpringBoot 中读取环境变量)
                  Tomcat 8 - context.xml use Environment Variable in Datasource(Tomcat 8 - context.xml 在数据源中使用环境变量)
                  Issue with JAVA_HOME(JAVA_HOME 的问题)

                    <legend id='fSxid'><style id='fSxid'><dir id='fSxid'><q id='fSxid'></q></dir></style></legend>
                    <i id='fSxid'><tr id='fSxid'><dt id='fSxid'><q id='fSxid'><span id='fSxid'><b id='fSxid'><form id='fSxid'><ins id='fSxid'></ins><ul id='fSxid'></ul><sub id='fSxid'></sub></form><legend id='fSxid'></legend><bdo id='fSxid'><pre id='fSxid'><center id='fSxid'></center></pre></bdo></b><th id='fSxid'></th></span></q></dt></tr></i><div id='fSxid'><tfoot id='fSxid'></tfoot><dl id='fSxid'><fieldset id='fSxid'></fieldset></dl></div>

                      <bdo id='fSxid'></bdo><ul id='fSxid'></ul>

                      <small id='fSxid'></small><noframes id='fSxid'>

                      <tfoot id='fSxid'></tfoot>
                        <tbody id='fSxid'></tbody>