Setting the environment for ProcessBuilder

前端 未结 6 1053
囚心锁ツ
囚心锁ツ 2020-12-06 17:14

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 proce

6条回答
  •  离开以前
    2020-12-06 17:42

    On Linux:

    String path = System.getenv("HOME");
    
    ProcessBuilder pb = new ProcessBuilder("/bin/bash","-c","export PATH=" +
        "PATH-TO-ADD" + ":" + path + " && exec");
    

    In this case the PATH variable is updated as per the need and the executable is searched in new $PATH. This worked for me on Linux.

提交回复
热议问题