For Unix platforms at least, you should be able to do this:
executablePath = isAbsolute($0) ? dirname($0) : cwd().dirname($0)
That absolutely does not work, as already pointed out. Ths looks like a reasonable reference implementation (LGPL), though:
http://www.opensource.apple.com/darwinsource/10.3/libiconv-9/libiconv/srclib/ progreloc.c
On Windows and Linux, it uses Win32 and /proc to provide a robust implementation. Otherwise, it guesses by looking at $0 and $ENV{PATH}.
My guess is that there's a more reliable (and non-portable) way to do this on Mac OS X, since Carbon applications need to reliably open the resource fork of the executable.
—
Gordon Henriksen [EMAIL PROTECTED]