SPUG: finding full path to itself
DeRykus, Charles E
charles.e.derykus at boeing.com
Wed May 31 09:36:49 PDT 2006
On Tue, May 30, 2006 at 02:36:20PM -0700, Satish Gupta wrote:
> When I a stand-alone script is running, how can this script determine
> it's own absolute path in a portable manner?
>
> I notice that $0 works differently on different OS's. On some it gives
> full path and not on others.
>> Along those same lines how can I, in a portable manner, determine the
full path
>> to the perl executable?
>> Kwiki has a hardcoded path of #!/usr/bin/perl which is okay for most
non-windows
>> machines, but I'm stuck with a windows box for right now. It is not
a big deal
>> as I just edit index.cgi after every update (or I could edit the
Kwiki::Files file)
>> but it would be nice to automagically figure that out when installing
Kwiki.
The recommended safe way in `perldoc perl` is to use the installed
executable.
On Win32 for instance:
C:\>perl -V:perlpath
perlpath='C:\Perl\bin\perl.exe';
C:\>perl -V:_exe
_exe='.exe';
>From `perldoc perlvar`:
Because many operating systems permit anyone with
read access to the Perl program file to make a copy
of it, patch the copy, and then execute the copy,
the security-conscious Perl programmer should take
care to invoke the installed copy of perl, not the
copy referenced by $^X. The following statements
accomplish this goal, and produce a pathname that
can be invoked as a command or referenced as a file.
use Config;
$secure_perl_path = $Config{perlpath};
if ($^O ne 'VMS')
{$secure_perl_path .= $Config{_exe}
unless $secure_perl_path =~ m/$Config{_exe}$/i;}
--
Charles DeRykus
More information about the spug-list
mailing list