title: How to set an environment variable in Java using exec?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java">How do I set environment variables from Java?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm trying to set an environment variable, and read it back to verify it was actually set.</p>
  
  <p>I've got the following : </p>
  
  <pre><code>import java.io.IOException;
  
  public class EnvironmentVariable
  {
      public static void main(String[] args) throws IOException
      {
          Runtime.getRuntime().exec("cmd.exe set FOO=false");
  
          String s = System.getenv("FOO");
          System.out.println(s);
      }
  }
  </code></pre>
  
  <p>However, it appears that <code>FOO</code> is always null, meaning its probably not set correctly.</p>
  
  <p>Do I have the exec command correct? The javadocs state it can take a string argument as the command.</p>
  
  <p>Any ideas?</p>