Re: Can perl check if executable exists
- From: "l v" <veatchla@xxxxxxxxx>
- Date: 16 Mar 2006 17:54:20 -0800
Bart Lateur wrote:
Paul Lalli wrote:
Random Task wrote:
Before I call make I would like to see if it is in my PATH. If it is not
in my Path i would like to check for make in a couple hardcoded visual
studio directories ... i.e. VS .NET or VS6 ...
Here's a brute-force algorithm:
1) Get the PATH variable, via the %ENV hash (so, $path = $ENV{PATH} )
2) Split on whatever your path separator is to obtain a list of
directories in your PATH.
3) Loop through each directory,
3a) Each iteration of the loop, test the existance of the path composed
of the current directory and the filename
4) If still not found, test the existance of the path composed of your
hardcoded directory and the filename
What could also be helpful is path() in File::Spec, or
File::Spec::Functions. Like this:
use File::Spec;
my @path = File::Spec->path;
The only problem I see with (3a), is that you don't take care of file
extensions. For example, if you search for "nmake", you should really
test existence of "nmake.exe". That is not easy to do portable -- Unix
doesn't use executable file extensions. And I don't know of a (standard)
module that can take care of that, like File::Spec.
What about testing for executable permissions (-x) if on Unix OS? -x
on win2k seems to work with limited testing. As far as the windows
extensions -- I just replyed to a different post regarding the use of
$ENV{'PATHEXT'}.
Len
.
- References:
- Can perl check if executable exists
- From: Random Task
- Re: Can perl check if executable exists
- From: Paul Lalli
- Re: Can perl check if executable exists
- From: Bart Lateur
- Can perl check if executable exists
- Prev by Date: Re: Can perl check if executable exists
- Next by Date: Re: Determine read/write status of filehandles connected to memory objects.
- Previous by thread: Re: Can perl check if executable exists
- Next by thread: Re: Can perl check if executable exists
- Index(es):
Relevant Pages
|