Need to find a file on the execution PATH

Discussion in 'Perl Misc' started by davido@codethought.nospamforme.com, Mar 2, 2004.

  1. Guest

    Hey there...

    Does anyone know of a (cross platform - works in Win32 /or/ *nix) way
    to figure out of a executable program is on a search path? For
    example, to find if foobar.exe is in the Win32 PATH?

    Googling didn't turn up suitable results (but I might have not not
    used the right search criteria).

    TIA.

    DavidO
    , Mar 2, 2004
    #1
    1. Advertising

  2. Paul Lalli Guest

    On Tue, 2 Mar 2004, wrote:

    > Hey there...
    >
    > Does anyone know of a (cross platform - works in Win32 /or/ *nix) way
    > to figure out of a executable program is on a search path? For
    > example, to find if foobar.exe is in the Win32 PATH?
    >
    > Googling didn't turn up suitable results (but I might have not not
    > used the right search criteria).



    Take a look at the modules File::Find and File::Spec (specifially, the
    File::Spec->path() function). Both are in the standard distribution.

    Paul Lalli
    Paul Lalli, Mar 2, 2004
    #2
    1. Advertising

  3. Guest

    On Tue, 2 Mar 2004 11:54:29 -0500, Paul Lalli <>
    wrote:

    >Take a look at the modules File::Find and File::Spec (specifially, the
    >File::Spec->path() function). Both are in the standard distribution.


    Perfect! Do you know how to squelch the messages when find *doesn't*
    find something tho? I'm seeing this:

    Can't stat C:\Perl\bin\/csdfommand.com: No such file or directory
    at sbt_build_deploy_tools.pm line 535
    Can't stat C:\Program Files\Borland\BDS\1.0\Bin/csdfommand.com: No
    such file or
    directory
    at sbt_build_deploy_tools.pm line 535
    Can't stat c:\j2sdk1.4.1_05\bin/csdfommand.com: No such file or
    directory
    at sbt_build_deploy_tools.pm line 535
    Can't stat C:\WINDOWS\system32/csdfommand.com: No such file or
    directory
    , Mar 2, 2004
    #3
  4. Guest

    On Tue, 02 Mar 2004 11:40:26 -0800,
    "" <> wrote:

    >On Tue, 2 Mar 2004 11:54:29 -0500, Paul Lalli <>
    >wrote:
    >
    >>Take a look at the modules File::Find and File::Spec (specifially, the
    >>File::Spec->path() function). Both are in the standard distribution.

    >
    >Perfect! Do you know how to squelch the messages when find *doesn't*
    >find something tho? I'm seeing this:


    Nevermind.. Apparently that was due to a "use diagnostics" statement
    in my perl module.

    Thanks again!
    , Mar 2, 2004
    #4
  5. "" wrote:
    >
    > Does anyone know of a (cross platform - works in Win32 /or/ *nix) way
    > to figure out of a executable program is on a search path? For
    > example, to find if foobar.exe is in the Win32 PATH?
    >
    > Googling didn't turn up suitable results (but I might have not not
    > used the right search criteria).


    use Env '@PATH';

    my $program = 'foobar.exe';

    -x and print "$_\n" for map "$_/$program", @PATH;



    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Mar 2, 2004
    #5
  6. Joe Smith Guest

    John W. Krahn wrote:

    > "" wrote:
    >
    >>Does anyone know of a (cross platform - works in Win32 /or/ *nix) way
    >>to figure out of a executable program is on a search path? For
    >>example, to find if foobar.exe is in the Win32 PATH?
    >>
    >>Googling didn't turn up suitable results (but I might have not not
    >>used the right search criteria).

    >
    >
    > use Env '@PATH';
    >
    > my $program = 'foobar.exe';
    >
    > -x and print "$_\n" for map "$_/$program", @PATH;


    Not very cross-platform. For just Win32 and *nix, I would use
    my $program = 'foobar';
    -x and print "$_\n" for map {"$_/$program", "$_/$program.exe"}, @PATH;

    But to do it right means also checking for .bat and .cmd, and using
    File::Spec so that it will work on MacOS Classic and OpenVMS.
    -Joe
    Joe Smith, Mar 3, 2004
    #6
  7. Ben Morrow Guest

    Joe Smith <> wrote:
    > John W. Krahn wrote:
    >
    > > use Env '@PATH';
    > >
    > > my $program = 'foobar.exe';
    > >
    > > -x and print "$_\n" for map "$_/$program", @PATH;

    >
    > Not very cross-platform. For just Win32 and *nix, I would use
    > my $program = 'foobar';
    > -x and print "$_\n" for map {"$_/$program", "$_/$program.exe"}, @PATH;


    Use $Config{_exe} for more portability.

    > But to do it right means also checking for .bat and .cmd


    Hmmm.... if you want to do this, you need to check for Win32 and then
    use the appropriate environment var; I'd probably just stick to exe.

    > , and using
    > File::Spec so that it will work on MacOS Classic and OpenVMS.


    ....and anywhere else...

    Ben

    --
    I've seen things you people wouldn't believe: attack ships on fire off
    the shoulder of Orion; I watched C-beams glitter in the dark near the
    Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
    Time to die.
    Ben Morrow, Mar 3, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Wake
    Replies:
    2
    Views:
    464
    David Wake
    Feb 9, 2005
  2. Kris

    changing execution path

    Kris, Sep 18, 2003, in forum: C++
    Replies:
    6
    Views:
    505
    Kevin Goodsell
    Sep 18, 2003
  3. Wybo Dekker
    Replies:
    1
    Views:
    328
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    374
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    783
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page