Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Java让getenv在Windows中工作_Java_Processbuilder_Getenv - Fatal编程技术网

使用Java让getenv在Windows中工作

使用Java让getenv在Windows中工作,java,processbuilder,getenv,Java,Processbuilder,Getenv,嗨,我一直在努力让“getenv”正常工作。它将继续返回“线程中的异常”main“java.lang.UnsupportedOperationException”。我一直在阅读有关ProcessBuilder的文章,但根据下面的代码,我不太确定如何以及在何处实现它 我想要做的是,在满足条件时设置变量(“回归状态”、“更新”)和(“回归状态”、“过期”),并在Windows中通过cmd执行时返回值“更新”和“过期” public static void main(String[] args) th

嗨,我一直在努力让“getenv”正常工作。它将继续返回“线程中的异常”main“java.lang.UnsupportedOperationException”。我一直在阅读有关ProcessBuilder的文章,但根据下面的代码,我不太确定如何以及在何处实现它

我想要做的是,在满足条件时设置变量(“回归状态”、“更新”)和(“回归状态”、“过期”),并在Windows中通过cmd执行时返回值“更新”和“过期”

public static void main(String[] args) throws ClassNotFoundException {
    String run_type = args[0];
    String inputFile = args[1];

    System.out.println("RUN TYPE = "  + run_type);
    System.out.println("INPUT FILE = "  + inputFile);

    MiniData data = getValue(run_type, "LEM");

    if(run_type.equals("BUILD")){
        System.out.println("Script = " + data.getScript());
    }
    else if (run_type.equals("DEPLOY")){
        System.out.println("Script = " + data.getScript());
    }
    else if (run_type.equals("REGRESSION")){
        System.out.println("Runtime Version (DB) = " + data.getRuntime());
        String file_name =inputFile;

        if(data.getRuntime().equals(getRuntimeVersion(file_name)))
        {
            System.out.println("The version is up-to-date");
            System.getenv().put("REGRESSION_STATUS", "UPDATED");
            System.getenv().put("REGRESSION_VER", data.getRuntime());   
        }
        else 
        {
            System.out.println("This version is outdated");
            System.getenv().put("REGRESSION_STATUS", "OUTDATED");
            System.getenv().put("REGRESSION_VER", data.getRuntime() );
        }
    }
    else {
        System.out.println("You have not the correct value. Enter either BUILD/DEPLOY/REGRESSION");
    }
}   
谢谢

环境变量的类型。您不能像这里这样使用它来设置环境变量


只有在使用类或方法为子进程创建环境时,才能“设置”环境变量,但即使这样,也不能修改环境的副本。

必须使用C
putenv
和JNI,Java没有办法做到这一点。

那么,对于我想要实现的目标,有什么解决方案吗?如果一个进程设置了环境变量,它只会影响它自己的环境以及它将启动的子进程的环境。你没有生育任何孩子,那么你想达到什么目的呢?