check for file in $PATH

C

cerr

Hi There,

My perl script depends on a binary that may be in $PATH and i would
like to check for that file. How can I verify if the file is present
in $PATH without hard coding a full path?

Thanks,
Ron
 
F

Frank Seitz

cerr said:
My perl script depends on a binary that may be in $PATH and i would
like to check for that file. How can I verify if the file is present
in $PATH without hard coding a full path?

http://search.cpan.org/~tjenness/File-SearchPath/SearchPath.pm

Frank
--
Dipl.-Inform. Frank Seitz
Anwendungen für Ihr Internet und Intranet
Tel: +49 (0)4103/180301; Fax: -02; Industriestr. 31, D-22880 Wedel

Blog: http://www.fseitz.de/blog
XING-Profil: http://www.xing.com/profile/Frank_Seitz2
 
J

Jürgen Exner

cerr said:
My perl script depends on a binary that may be in $PATH and i would
like to check for that file. How can I verify if the file is present
in $PATH without hard coding a full path?

I suppose you could generalize FindBin to search for arbitrary files,
not just the perl binary.

Or simply use the external "which" utility.

Or just call it, maybe with innocent arguments, and analyse the return
value for the error code.

jue
 
M

m!thun

Use File::Spec->path here, or some wrapper. Not all platforms use a
:-separated PATH, and not all platforms call the pertinant env var 'PATH'..


Ditto: File::Spec->catfile, or a wrapper like Path::Class (highly
recommended).

Ben

I've been using File::Which. I think this is more portable and usable
than the other modules mentioned here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top