Ben's Bay

Welcome!

For whatever reason you're here now. What you see is interpreted by your browser and rendered by your machine; altered by the technology and finally by your perception.

There should be no question that this isn't a person, but it's something.

Movator Me

Rock Climbing

Rock climbing is an excellent sport and often brings adventure. In my enjoyment of both climbing and photography I've taken quite a few photos of rock climbing.

Photography

My photography is a mood, a passion, expressive, sharing, silly, sometimes forgotten.

Projects

Occasionally I take on a side project, sometimes just for me and sometimes with or for others.

Family

Some of my family are on the web too!

Java

I'm pleased to have discovered how a Java program can modify its own environment variables, so that programs or libraries subsequently loaded can use them. Here it is:

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;

/** This class sets environment variables, using libc via JNA. 
 * @author Ben Damm
 */
public class SetEnv {

    // This is the standard, stable way of mapping, which supports extensive
    // customization and mapping of Java to native types.
    public interface CLibrary extends Library {
        CLibrary INSTANCE = (CLibrary)
            Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"),
                               CLibrary.class);
    
        int setenv(String name, String value, int overwrite);
        String getenv(String name);
    }

    public static void main(String[] args) {
		String var = "VARNAME";
		String val = CLibrary.INSTANCE.getenv(var);
        System.out.printf("%s\t%s\n", var, val);
        CLibrary.INSTANCE.setenv(var, "WOOOOHOOO!", 1);
		val = CLibrary.INSTANCE.getenv(var);
        System.out.printf("%s\t%s\n", var, val);
    }
}

Fin

Tact involves skill and patience; patience involves love.

Ben Damm
San Francisco CA, USA
Wikipedia Affiliate Button

Join Zipcar and get $50 in free driving!