Mangling An Applications Path

August 15, 2007

I was looking to get rid of using some environment variables in the app I do at work for several reasons. One, you can’t grab fresh environment variables on the fly (or at least I can’t) so if anything needs to be changed, you have to do a hard kill and restart the program. Two is that requiring some obscure, application specific environment variables seems a little silly to me, it’s excessive and adds bothersome configuration.

What I really needed was a way to open a config file that always resides in the same directory as the application. To do that I had to take the execution path (e.g. argv[0]) and chop it up a bit so that I can always get to that directory. I’m sure there is a better way to do this, and it wouldn’t work if you had the application in your $PATH, because then argv[0] would just be the executable name. Regardless of the caveats, it works nicely for me and makes me feel better about myself now that I can frag the environment variables.

Categories: Geek
Tags: , ,

Leave A Comment

Your email will not be published.