Re: absolute path of current process



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();

HTH,
--
Offer Kaye
.



Relevant Pages

  • Re: absolute path of current process
    ... >> the only OS independent (unix/win32) way to determine the absolute path of ... > use Cwd qw; ... absolute path, with relative path, from cron, etc.). ...
    (perl.beginners)
  • Re: [PHP] __sleep() strange behavior with file writting and SESSION using
    ... I'am used to always using an absolute path, I don't know why this time I ... PHP General Mailing List ... but during the startup/shutdown phases of php there is no script, the CWD ...
    (php.general)
  • Re: Cant Install Perl as Non-Root
    ... File::Find is trying to work out its cwd, which means it needs to be ... be an absolute path to miniperl in the build directory. ... I suspect you may not be able to fix this, as MakeMaker needs to know ...
    (comp.lang.perl.misc)
  • Re: open_basedir
    ... you cd to /somedir and execute the script: it fails. ... , PHP expects the text file to be in /somedir, simular to: ... absolute path works, because this doesn't take the cwd into account. ...
    (comp.lang.php)
  • Re: absolute path of current process
    ... >> the only OS independent (unix/win32) way to determine the absolute path of ... Paul Johnson - paul@xxxxxxxx ... Prev by Date: ...
    (perl.beginners)