Java Runtime.getRuntime().exec() appears to be overwriting $PATH

前端 未结 1 701
你的背包
你的背包 2021-01-22 21:11

For a project to automate some mutation adequacy testing, I\'m trying to make GoLang from source from inside a Java program. I have been able to make it from source in the Termi

相关标签:
1条回答
  • 2021-01-22 21:45

    Runtime.exec was replaced by ProcessBuilder twelve years ago, as part of Java 1.5.

    Among its many superior features is the ability to add to the existing environment:

    ProcessBuilder builder = new ProcessBuilder("./all.bash");
    builder.inheritIO();
    
    builder.directory(
        new File(System.getProperty("user.home") + "/Desktop/go/src"));
    
    builder.environment().put("CC", "/usr/bin/clang");
    builder.environment().put("GOROOT_BOOTSTRAP", "/usr/local/go");
    builder.environment().put("CGO_ENABLED", "0");
    
    builder.start();
    
    0 讨论(0)
提交回复
热议问题