Environment Variables - II

29 May 2008

A brief overview of how to retrieve environment variables is presented in first part of this post. Do read that one first.

An interesting example is presented below. We are only printing the non null environment variables.

...
        for (String env: args) {
            String value = System.getenv(env);
            if (value != null) {
                System.out.format("%s=%s%n", env, value);
            } else {
                System.out.format("%s is not assigned.%n", env);
            }
        }
...

You may want to pass environment variables to other process. This is possible. A ProcessBuilder object can be used to create a new process. In this way, the default set of environment variables is passed to the new process and this set is same as provided to the application’s virtual machine process. The application can change this set using ProcessBuilder.environment.

del.icio.us:Environment Variables - II  digg:Environment Variables - II  spurl:Environment Variables - II  wists:Environment Variables - II  simpy:Environment Variables - II  newsvine:Environment Variables - II  blinklist:Environment Variables - II  furl:Environment Variables - II  reddit:Environment Variables - II  fark:Environment Variables - II  blogmarks:Environment Variables - II  Y!:Environment Variables - II  smarking:Environment Variables - II  magnolia:Environment Variables - II  segnalo:Environment Variables - II  gifttagging:Environment Variables - II

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Environment Variables - II

Leave a Reply