Tuesday, January 29, 2008

segregating environment variables

Whenever you work with different version of a product at a single time, you run into overriding environment variables.

lets take Java SDK as example, you may have the JAVA_HOME pointed to JDK1.5 for the project you work on production deployment. At the same time you may also need to have JAVA_HOME pointed to JDK6 for your fun projects.

In windows you could have a batch command file that sets the correct environment variable. You could execute the batch file every time before you run any scripts that refer the JAVA_HOME variable. This is nice.

To add to it, you can put those .bat file in system path (i.e. c:\windows\system32) so you call that bat file from any directory.

However when you click this bat file, it executes the batch commands in it and exits. The scope of those new variables set is also exactly till it exits. This isn't of much use since you can't start working on the environment with the desired settings on the click of mouse.

To accomplish that trick just Right Click and create a shortcut in desktop and add following lines in the target location of the shortcut.
c:/windows/system32/cmd.exe /k c:/setenv.bat

in this the '/k' argument to the command line application tells it to execute the script and wait for further commands.

So by this you can click the shortcut to get a console opened and ready to accept commands.

You could also change buffer settings and screen settings for the console, so you get desired command console as you want.

N.B. even though windows shell is not that useful you can make it so if you add something like this.
UNIX Utilities 

but still UNIX rocks!

1 comment:

disown said...

Or, you can press Win+Break -> Advanced -> Environment variables. These apply to all cmd:s opened after the variables have been set, and provide system and user-level variables. I would argue that this is better than for instance Debian, which only has /etc/environment

Recommended Blog Posts