Find executables on windows

You asked...

at least on my system the Windows directory, SYSTEM and SYSTEM32 are
also in the PATH, so this will be ok in almost all cases I guess.
Depending what you are about to do I would suggest checking '.' also and
try other extensions than exe. My PATHEXT includes

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.RB;.RBW

So this may be important, at least if you don't know the complete
filename beforehand.

cheers

Simon

···

-----Original Message-----
From: Ara.T.Howard [mailto:Ara.T.Howard@noaa.gov]
Sent: Tuesday, September 13, 2005 4:18 PM
To: ruby-talk ML
Subject: Re: find executables on windows

On Tue, 13 Sep 2005, Kroeger Simon (ext) wrote:

> MSDN, CreateProcess:
>
> ...If the filename does not contain a directory path, the system
> searches
> for the executable file in the following sequence:
>
> - The directory from which the application loaded.
>
> - The current directory for the parent process.
>
> - Windows 95 and Windows 98: The Windows system directory.
> Use theGetSystemDirectory function to get the path of
this directory.
>
> - Windows NT: The 32-bit Windows system directory.
> Use the GetSystemDirectory function to get the path of this
> directory.
> The name of this directory is SYSTEM32.
>
> - Windows NT: The 16-bit Windows system directory.
> There is no Win32 function that obtains the path of this
directory,
> but it is searched. The name of this directory is SYSTEM.
>
> - The Windows directory. Use theGetWindowsDirectory
function to get the
>
> path of this directory.
>
> - The directories that are listed in the PATH environment variable.
>
> erm, yes, that's it! :slight_smile:

i think i'll settle for PATH :wink:

if was thinking more brute force:

...

   glob = File::join(dirname, basename) << '*'

   candidates = Dir[ glob ].select{|entry| File::executable? entry}

   return candidates.shift unless candidates.empty?

...

since, afaik, PATHEXT does not imply some sort of ordering or precedecne.
seem right?

-a

···

On Tue, 13 Sep 2005, Kroeger Simon (ext) wrote:

You asked...

at least on my system the Windows directory, SYSTEM and SYSTEM32 are
also in the PATH, so this will be ok in almost all cases I guess.
Depending what you are about to do I would suggest checking '.' also and
try other extensions than exe. My PATHEXT includes

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.RB;.RBW

--

email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna

===============================================================================

Hi,

At Tue, 13 Sep 2005 23:25:25 +0900,
Kroeger Simon (ext) wrote in [ruby-talk:155937]:

Depending what you are about to do I would suggest checking '.' also and
try other extensions than exe. My PATHEXT includes

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.RB;.RBW

So this may be important, at least if you don't know the complete
filename beforehand.

Currently, ruby.exe doesn't see PATHEXT.

···

--
Nobu Nakada

since, afaik, PATHEXT does not imply some sort of ordering or precedecne.
seem right?

The order _is_ important. With PATHEXT=.com;.exe;.bat..., foo.com will be
preferred to foo.exe, which in turn will be preferred to foo.bat, etc.

Loop through PATH first (prepend "."), PATHEXT second, both in order.

Cheers,
Dave