title: ProcessBuilder environment variable in java
body: <p>I'm trying to add a environment variable for a ProcessBuilder object but then when I call on that new variable in the ProcessBuilder I get an error.
  this is how I build the Process</p>
  
  <pre><code>public class OTU
  {
      public static void main(String[] args) throws Exception
      {
          ProcessBuilder pb = new ProcessBuilder();
          Map&lt;String, String&gt; env = pb.environment();
          //set environment variable u
          env.put("u", "util/");
  
          pb.command("echo $u");
          Process p = pb.start();
          String output = loadStream(p.getInputStream());
          String error  = loadStream(p.getErrorStream());
          int rc = p.waitFor();
          System.out.println("Process ended with rc=" + rc);
          System.out.println("\nStandard Output:\n");
          System.out.println(output);
          System.out.println("\nStandard Error:\n");
          System.out.println(error);
      }
  
      private static String loadStream(InputStream s) throws Exception
      {
          BufferedReader br = new BufferedReader(new InputStreamReader(s));
          StringBuilder sb = new StringBuilder();
          String line;
          while((line=br.readLine()) != null)
              sb.append(line).append("\n");
          return sb.toString();
      }
  }
  </code></pre>
  
  <p>I get the error</p>
  
  <pre><code>Exception in thread "main" java.io.IOException: Cannot run program "$u": java.io.IOException: error=2, No such file or directory
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:475)
      at ca.utoronto.siseq_1_2.OTU.main(OTU.java:22)
  Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
      at java.lang.UNIXProcess.&lt;init&gt;(UNIXProcess.java:164)
      at java.lang.ProcessImpl.start(ProcessImpl.java:81)
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:468)
      ... 1 more
  </code></pre>
  
  <p>I dont understand why I am getting the error if I just set the variable for this Process.
  Please help me how to set the env variable so I can use it in the ProcessBuilder.</p>