Friday 25 November 2011

Environmental Variables... We meet again!!!

So for those of you who don't know what Environmental Variables are here is a quick and dirty explaination. When you open the command prompt/terminal in your Windows, Mac, Unix or Linux computer and type a command the operating system looks for that command in a bunch of folders/directories in your file system. These bunch of folders is called the "Path" variable which is basically just a string that gives the absolute path to the folder that contains different commands. So on the Windows side of things some of the places that the system looks into include.
C:\Windows;
C:\Windows\system32;
And loads of other places. In the Linux/Unix/Mac side of things one of the directories include.
\usr\bin;
\usr\local\bin;
And loads some other places that usually depends on your flavor of the operating system.

If you are interest in finding out your path variable in the command prompt/terminal type this for Windows users:

echo %PATH% (Windows will accept everything in small letters)

On the Linux/Unix/Mac side of things type in:

echo $PATH (Depending on the shell and the Linux variant you are running it may accept things in small letters but to be safe use caps).

Now since I have been using Ubuntu 11.10 for about a month or so exclusively I have become used to how you can add software packages and commands to the list of commands that are built into Linux. This process can probably also be called softlinking applications. This therefore, allows me to stay in the terminal and when I want I can open the program that I want with a simple command. If you are interested in seeing how to soft link applications in Linux please refer to this article not written by me.

On the Windows side of things it is a bit different instead of creating a link to the application you want to be available in the command line you simply add the path to the folder to the Environmental variable by following the following simple steps.

  • Right-click on the "My Computer" icon on the desktop or press Windows + Pause/Break (another shortcut that I need to add to the previous post).
  • Click on "Advanced system settings".
  • Then click on "Environment Variables...".
  •  Look for a variable called "PATH" and double-click it or select it and click on "Edit".
  • In the "Variable value:" textbox at the end of the string that already exists add a semi-colon if its not already there and paste the path to the folder that your interested in. Note the path has to be the absolute path.
And thats it. At this point some of you might be asking why I would bother with such an easy pocedure? Well here is where things get slightly complicated and interesting. You see Windows has a character limit for the length of the variable which is 1027 (which if you ask me is a weird number) which is OK for normal users but with me having installed Perl, Python, GNU gcc and a bunch of other command line utilities this variable has been maxed out and can not take any more values. So I am determined to find another way around it.

The goal for this exercise is to have the adb tool available to me in the command line so I don't have to be in the Android-SDK folder and in the Platform-Tools folder to be able to access it. For those who don't know adb is a command line utility that is part of the Android SDK for developing applications and connecting to your device through the terminal and accessing things that even Eclipse with ADT installed will not let you.

Attempt 1
So, since I am so used to the Linux way of doing things I thought making a shortcut of the executable file and placing that in the C:\Windows directory would do the trick. So after I made a shortcut to the adb executable and placed it in the Windows folder and tired to run in the command line this was the result.





OK so maybe I should have renamed the shortcut so the name is just "adb.exe". So I did the renaming and still same result :(. Needless to say I was just a bit annoyed at this point in time. Although guess what, even though I have extensions turned on and I had explicitly named the file how I wanted it to be named when I did a "dir" command guess what I notice.
Yup... Windows will add the lnk extension even though I had renamed it. OK no problem so the lnk extension is still there I decided to rename the file in the command prompt itself so that it doesn't have the lnk extension.
So I have reached a deadend. I know that the program can be executed on the command prompt but thats only if I am in the folder that contains the file or if the path variable has been set.

So I leave you guys at a bit of a sad ending. I am continuing my pursuit or finding a way to solve this problem. Unfortunately making a symbollic link to the application doesn't solve the problem either. If anyone has any ideas please let me know as well.