Re: Can perl check if executable exists



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

.



Relevant Pages

  • Re: Convert *.img to *.iso?
    ... | does just executing a "mv" to *.iso really work? ... Extensions are just labels, no more meaningful than calling a ... a lot of tools don't care about the extension. ...
    (alt.linux)
  • Re: Viewing REAL values in Hex Format
    ... (in 5 lines or less without depending on compiler extensions)? ... with appropriate care to the sizes of things. ...
    (comp.lang.fortran)
  • Re: is variant-length array declaration standard compatible?
    ... >> At least in the GNU case you misused the compiler. ... >> Otherwise it compiles a mishmash of extensions. ... Why bother? ... "I don't really care about being right you know, ...
    (comp.lang.c)
  • Re: is C useful ?
    ... Kenneth Brody wrote: ... > Aggro wrote: ... >> You might need to use some extensions of C. ... It's always important to take care and open /dev/time O_RDONLY. ...
    (comp.lang.c)