Re: absolute path of current process
- From: rabbit@xxxxxxxxx (Peter Rabbitson)
- Date: Sat, 28 May 2005 12:33:48 -0500
On Thu, May 26, 2005 at 02:26:29PM +0300, Offer Kaye wrote:
> On 5/26/05, Peter Rabbitson <rabbit@xxxxxxxxx> wrote:
> > Is this:
> >
> > my $path = [File::Spec->splitpath (File::Spec->rel2abs ($0))]->[1];
> >
> > the only OS independent (unix/win32) way to determine the absolute path of
> > the directory which contains the current process, or there is a less cryptic
> > way that I am overlooking?
> >
>
> What do you mean by "current process"?
> If you mean "the path to the currently running executable" ($0), You
> can use a combination of the abs_path function from Cwd together with
> "dirname" from File::Basename :
> use Cwd qw(abs_path);
> use File::Basename qw(dirname);
> my $path = dirname(abs_path($0));
>
> However please note that the current process may be running in an
> entirely different directory then the one that hold the executable. To
> find the current directory, use:
> use Cwd qw(cwd);
> my $path = cwd();
I meant the absolute dir containing the executable. Thing is I want to throw
a config file in the same dir that will be found regardless of how the thing
got started (from the program dir with ./, from a different dir with
absolute path, with relative path, from cron, etc.). In other words exactly
what you proposed.
Btw looking at the source both you and mine methods end up using the same
core modules. I guess for this there isn't really TIMTOWTDI. OTOH mine
does not pollute namespace and yours is more readable. Counts as more than
one way I guess :)
Thanks
.
- References:
- absolute path of current process
- From: Peter Rabbitson
- Re: absolute path of current process
- From: Offer Kaye
- absolute path of current process
- Prev by Date: Re: count rows without count(*)
- Next by Date: Database independent code
- Previous by thread: Re: absolute path of current process
- Next by thread: RE: search a file
- Index(es):
Relevant Pages
|