Saturday, July 17, 2010

Environment Variables in Windows


Being a computer engineering student, I had to face Java language this year.

On the first lab some instructions were given to run commands prior compiling (Setting path.)
set path=c:\program files\java\jdk1.6.0\bin

Surprisingly (for me) just running javac command then worked. I knew there was no command called "javac" and the current directory in cmd did not have any "javac" file.

Curiosity bubbled and I asked the instructor of this, and he explained:

The command "set path" alters the default-set system path "C:\windows" and "C:\windows\system32".

It can be verified by My Computer > Properties > Advanced tab > Environment Variables Button.






















Hence First lesson: System path (Under Environment Variables) is like virtual current directory. You can execute exe's lying in these folders, just like you execute them as if they are in your current directory.

Lemme explain,

Suppose there is an executable "temp.exe" in directory D:\temp. When you start command prompt, you are at c:\Documents and settings\

Now try to run "temp.exe".

Failed ? Eh ?

Reason is, there is no file called "temp.exe" in your current folder.

Navigate to D:\temp\ and then run "temp.exe". That goes well.

So to run any executable just by name (as we did by just typing "javac") we need to be in that directory.(My perception before lab)

But windows provides a mechanism through which you can setup another directories virtually as your current directories and execute files in them as if they were in your current directory.

Best example could be "notepad". Running this command opens up notepad editor. The executable for notepad is located @ C:\windows\system32 folder. Hence this directory being set as path by default we can run files in this folder just by names.

When I altered the path by "Set path" command, I could no longer run "notepad". It had the error.


Hence the confusion waded away and I carried on with Java.

No comments:

Post a Comment