title: Java Runtime.getRuntime().exec() appears to be overwriting $PATH
body: <p>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 Terminal, and have tried using that command in Java's <code>Runtime.getRuntime().exec()</code> command:</p>
  
  <pre><code>String[] envp = new String[3];
  envp[0] = "CC=/usr/bin/clang";
  envp[1] = "GOROOT_BOOTSTRAP=/usr/local/go";
  envp[2] = "CGO_ENABLED=0";
  Runtime.getRuntime().exec("./all.bash", envp, "$HOME/Desktop/go/src");
  </code></pre>
  
  <p>The equivalent command to this works fine in the Terminal. Running this code in java (And printing the output) gets the following:</p>
  
  <pre><code>./all.bash
  ##### Building Go bootstrap tool.
  cmd/dist
  go tool dist: FAILED: uname -r: exec: "uname": executable file not found in $PATH
  </code></pre>
  
  <p>So that's weird that it can't find <code>uname</code>. Again, if I enter <code>'uname'</code> on the Terminal, it works fine. So I found the directory of <code>uname</code> ('which uname' gives <code>'/usr/bin/uname'</code>) and set <code>$PATH</code> to that for this command:</p>
  
  <pre><code>String[] envp = new String[4];
  envp[0] = "CC=/usr/bin/clang";
  envp[1] = "GOROOT_BOOTSTRAP=/usr/local/go";
  envp[2] = "CGO_ENABLED=0";
  envp[3] = "PATH=/usr/bin";
  Runtime.getRuntime().exec("./all.bash", envp, "$HOME/Desktop/go/src");
  </code></pre>
  
  <p>And that instead gets the output:</p>
  
  <pre><code>./all.bash
  env: bash: No such file or directory
  </code></pre>
  
  <p>So when I set the path, it can't find the program in the directory. This suggests to me that when <code>Runtime.getRuntime().exec()</code> is called, it overwrites <code>$PATH</code> to be the directory I passed it, then overwrites the environment variables I gave it. But in order for <code>./all.bash</code> to work, I need both paths to be in the <code>$PATH</code> variable. How can I do this?</p>
  
  <p>On Mac OS X 10.11.6.</p>