.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.13)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.ie \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.el \{\
. de IX
..
.\}
.\" ========================================================================
.\"
.IX Title "File::Which 3"
.TH File::Which 3 "2018-12-31" "perl v5.10.1" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
File::Which \- Perl implementation of the which utility as an API
.SH "VERSION"
.IX Header "VERSION"
version 1.23
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 2
\& use File::Which; # exports which()
\& use File::Which qw(which where); # exports which() and where()
\&
\& my $exe_path = which \*(Aqperldoc\*(Aq;
\&
\& my @paths = where \*(Aqperl\*(Aq;
\& # Or
\& my @paths = which \*(Aqperl\*(Aq; # an array forces search for all of them
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
File::Which finds the full or relative paths to executable programs on
the system. This is normally the function of \f(CW\*(C`which\*(C'\fR utility. \f(CW\*(C`which\*(C'\fR is
typically implemented as either a program or a built in shell command. On
some platforms, such as Microsoft Windows it is not provided as part of the
core operating system. This module provides a consistent \s-1API\s0 to this
functionality regardless of the underlying platform.
.PP
The focus of this module is correctness and portability. As a consequence
platforms where the current directory is implicitly part of the search path
such as Microsoft Windows will find executables in the current directory,
whereas on platforms such as \s-1UNIX\s0 where this is not the case executables
in the current directory will only be found if the current directory is
explicitly added to the path.
.PP
If you need a portable \f(CW\*(C`which\*(C'\fR on the command line in an environment that
does not provide it, install App::pwhich which provides a command line
interface to this \s-1API\s0.
.SS "Implementations"
.IX Subsection "Implementations"
File::Which searches the directories of the user's \f(CW\*(C`PATH\*(C'\fR (the current
implementation uses File::Spec#path to determine the correct \f(CW\*(C`PATH\*(C'\fR),
looking for executable files having the name specified as a parameter to
\&\*(L"which\*(R". Under Win32 systems, which do not have a notion of directly
executable files, but uses special extensions such as \f(CW\*(C`.exe\*(C'\fR and \f(CW\*(C`.bat\*(C'\fR
to identify them, \f(CW\*(C`File::Which\*(C'\fR takes extra steps to assure that
you will find the correct file (so for example, you might be searching for
\&\f(CW\*(C`perl\*(C'\fR, it'll try \fIperl.exe\fR, \fIperl.bat\fR, etc.)
.PP
\fILinux, *BSD and other UNIXes\fR
.IX Subsection "Linux, *BSD and other UNIXes"
.PP
There should not be any surprises here. The current directory will not be
searched unless it is explicitly added to the path.
.PP
\fIModern Windows (including \s-1NT\s0, \s-1XP\s0, Vista, 7, 8, 10 etc)\fR
.IX Subsection "Modern Windows (including NT, XP, Vista, 7, 8, 10 etc)"
.PP
Windows \s-1NT\s0 has a special environment variable called \f(CW\*(C`PATHEXT\*(C'\fR, which is used
by the shell to look for executable files. Usually, it will contain a list in
the form \f(CW\*(C`.EXE;.BAT;.COM;.JS;.VBS\*(C'\fR etc. If \f(CW\*(C`File::Which\*(C'\fR finds such an
environment variable, it parses the list and uses it as the different
extensions.
.PP
\fICygwin\fR
.IX Subsection "Cygwin"
.PP
Cygwin provides a Unix-like environment for Microsoft Windows users. In most
ways it works like other Unix and Unix-like environments, but in a few key
aspects it works like Windows. As with other Unix environments, the current
directory is not included in the search unless it is explicitly included in
the search path. Like on Windows, files with \f(CW\*(C`.EXE\*(C'\fR or <.BAT> extensions will
be discovered even if they are not part of the query. \f(CW\*(C`.COM\*(C'\fR or extensions
specified using the \f(CW\*(C`PATHEXT\*(C'\fR environment variable will \s-1NOT\s0 be discovered
without the fully qualified name, however.
.PP
\fIWindows \s-1ME\s0, 98, 95, MS-DOS, \s-1OS/2\s0\fR
.IX Subsection "Windows ME, 98, 95, MS-DOS, OS/2"
.PP
This set of operating systems don't have the \f(CW\*(C`PATHEXT\*(C'\fR variable, and usually
you will find executable files there with the extensions \f(CW\*(C`.exe\*(C'\fR, \f(CW\*(C`.bat\*(C'\fR and
(less likely) \f(CW\*(C`.com\*(C'\fR. \f(CW\*(C`File::Which\*(C'\fR uses this hardcoded list if it's running
under Win32 but does not find a \f(CW\*(C`PATHEXT\*(C'\fR variable.
.PP
As of 2015 none of these platforms are tested frequently (or perhaps ever),
but the current maintainer is determined not to intentionally remove support
for older operating systems.
.PP
\fI\s-1VMS\s0\fR
.IX Subsection "VMS"
.PP
Same case as Windows 9x: uses \f(CW\*(C`.exe\*(C'\fR and \f(CW\*(C`.com\*(C'\fR (in that order).
.PP
As of 2015 the current maintainer does not test on \s-1VMS\s0, and is in fact not
certain it has ever been tested on \s-1VMS\s0. If this platform is important to you
and you can help me verify and or support it on that platform please contact
me.
.SH "FUNCTIONS"
.IX Header "FUNCTIONS"
.SS "which"
.IX Subsection "which"
.Vb 2
\& my $path = which $short_exe_name;
\& my @paths = which $short_exe_name;
.Ve
.PP
Exported by default.
.PP
\&\f(CW$short_exe_name\fR is the name used in the shell to call the program (for
example, \f(CW\*(C`perl\*(C'\fR).
.PP
If it finds an executable with the name you specified, \f(CW\*(C`which()\*(C'\fR will return
the absolute path leading to this executable (for example, \fI/usr/bin/perl\fR or
\&\fIC:\ePerl\eBin\eperl.exe\fR).
.PP
If it does \fInot\fR find the executable, it returns \f(CW\*(C`undef\*(C'\fR.
.PP
If \f(CW\*(C`which()\*(C'\fR is called in list context, it will return \fIall\fR the
matches.
.SS "where"
.IX Subsection "where"
.Vb 1
\& my @paths = where $short_exe_name;
.Ve
.PP
Not exported by default.
.PP
Same as \*(L"which\*(R" in array context. Similar to the \f(CW\*(C`where\*(C'\fR csh
built-in command or \f(CW\*(C`which \-a\*(C'\fR command for platforms that support the
\&\f(CW\*(C`\-a\*(C'\fR option. Will return an array containing all the path names
matching \f(CW$short_exe_name\fR.
.SH "GLOBALS"
.IX Header "GLOBALS"
.ie n .SS "$IMPLICIT_CURRENT_DIR"
.el .SS "\f(CW$IMPLICIT_CURRENT_DIR\fP"
.IX Subsection "$IMPLICIT_CURRENT_DIR"
True if the current directory is included in the search implicitly on
whatever platform you are using. Normally the default is reasonable,
but on Windows the current directory is included implicitly for older
shells like \f(CW\*(C`cmd.exe\*(C'\fR and \f(CW\*(C`command.com\*(C'\fR, but not for newer shells
like PowerShell. If you overrule this default, you should \s-1ALWAYS\s0
localize the variable to the tightest scope possible, since setting
this variable from a module can affect other modules. Thus on Windows
you can get the correct result if the user is running either \f(CW\*(C`cmd.exe\*(C'\fR
or PowerShell on Windows you can do this:
.PP
.Vb 2
\& use File::Which qw( which );
\& use Shell::Guess;
\&
\& my $path = do {
\& my $is_power = Shell::Guess\->running_shell\->is_power;
\& local $File::Which::IMPLICIT_CURRENT_DIR = !$is_power;
\& which \*(Aqfoo\*(Aq;
\& };
.Ve
.PP
For a variety of reasons it is difficult to accurately compute the
shell that a user is using, but Shell::Guess makes a reasonable
effort.
.SH "CAVEATS"
.IX Header "CAVEATS"
This module has no non-core requirements for Perl 5.6.2 and better.
.PP
This module is fully supported back to Perl 5.8.1. It may work on 5.8.0.
It should work on Perl 5.6.x and I may even test on 5.6.2. I will accept
patches to maintain compatibility for such older Perls, but you may
need to fix it on 5.6.x / 5.8.0 and send me a patch.
.PP
Not tested on \s-1VMS\s0 although there is platform specific code
for those. Anyone who haves a second would be very kind to send me a
report of how it went.
.SH "SUPPORT"
.IX Header "SUPPORT"
Bugs should be reported via the GitHub issue tracker
.PP
<https://github.com/plicease/File\-Which/issues>
.PP
For other issues, contact the maintainer.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
.IP "pwhich, App::pwhich" 4
.IX Item "pwhich, App::pwhich"
Command line interface to this module.
.IP "IPC::Cmd" 4
.IX Item "IPC::Cmd"
This module provides (among other things) a \f(CW\*(C`can_run\*(C'\fR function, which is
similar to \f(CW\*(C`which\*(C'\fR. It is a much heavier module since it does a lot more,
and if you use \f(CW\*(C`can_run\*(C'\fR it pulls in ExtUtils::MakeMaker. This combination
may be overkill for applications which do not need IPC::Cmd's complicated
interface for running programs, or do not need the memory overhead required
for installing Perl modules.
.Sp
At least some older versions will find executables in the current directory,
even if the current directory is not in the search path (which is the default
on modern Unix).
.Sp
\&\f(CW\*(C`can_run\*(C'\fR converts directory path name to the 8.3 version on Windows using
\&\f(CW\*(C`Win32::GetShortPathName\*(C'\fR in some cases. This is frequently useful for tools
that just need to run something using \f(CW\*(C`system\*(C'\fR in scalar mode, but may be
inconvenient for tools like App::pwhich where user readability is a premium.
Relying on \f(CW\*(C`Win32::GetShortPathName\*(C'\fR to produce filenames without spaces
is problematic, as 8.3 filenames can be turned off with tweaks to the
registry (see <https://technet.microsoft.com/en\-us/library/cc959352.aspx>).
.IP "Devel::CheckBin" 4
.IX Item "Devel::CheckBin"
This module purports to \*(L"check that a command is available\*(R", but does not
provide any documentation on how you might use it.
.SH "AUTHORS"
.IX Header "AUTHORS"
.IP "\(bu" 4
Per Einar Ellefsen <pereinar@cpan.org>
.IP "\(bu" 4
Adam Kennedy <adamk@cpan.org>
.IP "\(bu" 4
Graham Ollis <plicease@cpan.org>
.SH "COPYRIGHT AND LICENSE"
.IX Header "COPYRIGHT AND LICENSE"
This software is copyright (c) 2002 by Per Einar Ellefsen <pereinar@cpan.org>.
.PP
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
Copyright 2K16 - 2K18 Indonesian Hacker Rulez