<tfoot id='ii3jh'></tfoot>

    <legend id='ii3jh'><style id='ii3jh'><dir id='ii3jh'><q id='ii3jh'></q></dir></style></legend>
  1. <small id='ii3jh'></small><noframes id='ii3jh'>

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

      在 Java 运行时设置 windows PATH 环境变量

      set windows PATH environment variable at runtime in Java(在 Java 运行时设置 windows PATH 环境变量)
          <legend id='JFSMR'><style id='JFSMR'><dir id='JFSMR'><q id='JFSMR'></q></dir></style></legend>

            <i id='JFSMR'><tr id='JFSMR'><dt id='JFSMR'><q id='JFSMR'><span id='JFSMR'><b id='JFSMR'><form id='JFSMR'><ins id='JFSMR'></ins><ul id='JFSMR'></ul><sub id='JFSMR'></sub></form><legend id='JFSMR'></legend><bdo id='JFSMR'><pre id='JFSMR'><center id='JFSMR'></center></pre></bdo></b><th id='JFSMR'></th></span></q></dt></tr></i><div id='JFSMR'><tfoot id='JFSMR'></tfoot><dl id='JFSMR'><fieldset id='JFSMR'></fieldset></dl></div>
            <tfoot id='JFSMR'></tfoot>
              <tbody id='JFSMR'></tbody>
          • <small id='JFSMR'></small><noframes id='JFSMR'>

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

                问题描述

                我有一个使用 Runtime.exec() 方法触发可执行文件的 java 程序.我正在使用将一组命令行参数作为一个参数,并将一些环境变量作为另一个参数的变体.

                I have a java program that fires off an executable using the Runtime.exec() method. I'm using the variant that takes in a set of command line params as one argument, and some environment variables as another argument.

                我尝试设置的环境变量是路径,所以我传入PATH=C:somepath".这不起作用.是否有一些技巧或任何替代方法.不幸的是,我坚持使用 Java 1.4.

                The environment variable I'm tryign to set is path, so i'm passing in "PATH=C:somepath". This does not work. Is there some trick to this or any alternatives. I am stuck to Java 1.4 unfortunately.

                推荐答案

                使用getenv 获取环境并修复它,然后使用 exec 执行 exec.

                Use getenv to get the environment and fix it up then use a flavour of exec to do the exec.

                这适用于其中包含路径的批处理文件.

                This works with a batch file that has path in it.

                package p;
                
                import java.util.*;
                
                public class Run {
                    static String[] mapToStringArray(Map<String, String> map) {
                        final String[] strings = new String[map.size()];
                        int i = 0;
                        for (Map.Entry<String, String> e : map.entrySet()) {
                            strings[i] = e.getKey() + '=' + e.getValue();
                            i++;
                        }
                        return strings;
                    }
                
                    public static void main(String[] arguments) throws Exception {
                        final Map<String, String> env = new HashMap<String, String>(System.getenv());
                        env.put("Path", env.get("Path") + ";foo");
                        final String[] strings=mapToStringArray(env);
                        Runtime.getRuntime().exec("cmd /C start foo.bat",strings);
                    }
                
                }
                

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

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

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    <bdo id='TxhvK'></bdo><ul id='TxhvK'></ul>
                  • <i id='TxhvK'><tr id='TxhvK'><dt id='TxhvK'><q id='TxhvK'><span id='TxhvK'><b id='TxhvK'><form id='TxhvK'><ins id='TxhvK'></ins><ul id='TxhvK'></ul><sub id='TxhvK'></sub></form><legend id='TxhvK'></legend><bdo id='TxhvK'><pre id='TxhvK'><center id='TxhvK'></center></pre></bdo></b><th id='TxhvK'></th></span></q></dt></tr></i><div id='TxhvK'><tfoot id='TxhvK'></tfoot><dl id='TxhvK'><fieldset id='TxhvK'></fieldset></dl></div>

                        <tbody id='TxhvK'></tbody>
                      <legend id='TxhvK'><style id='TxhvK'><dir id='TxhvK'><q id='TxhvK'></q></dir></style></legend>

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

                      1. <tfoot id='TxhvK'></tfoot>