On approximately 9/30/2003 11:03 AM, came the following characters from
the keyboard of Arms, Mike:

Dax T. Games [EMAIL PROTECTED] wrote:

How would I determine if a file existed in a directory in the PATH environment variable on a Windows box with Perl. If the file exists I want to return the full path to the file.

The functionality I want is similar to 'which' on Unix/Linux.


Dax, I second the folks recommending the Perl Power Tools (ppt)
if you want a straight implementation of Unix commands in Perl.

I wrote my own enhanced which.pl command which could do more than
the standard Unix "which":

... very interesting description deleted


This may be overkill for your needs, but I have found
this to be an extremely useful utility on my Win32
platform. I add to it occasionally when I find more
things that I want it to be able to do.

You can get it here:

http://marms.sourceforge.net/perl/

Hi Mike,


You have a very nice which.pl there, but I see two omissions, which may be resolved by the same coding...

1) You require that an executable have an extension from PATHEXT to be found... Windows doesn't. Extensionless executables are possible, and runnable. Further, extensions not on PATHEXT are runnable by specifying the extension when running it.

2) You require that an executable be specified to which without an extension... Windows permits specification of the extension... then you add each extension from PATHEXT in turn, and therefore do not find the executable.

I think both of these could be resolved by implicitly adding a "null" or "empty" extension to your internal copy of PATHEXT ... I'm not sure whether Windows checks that first or last, but you should figure that out, and do the same.

For example, I placed your which.pl in a directory on my path, but .PL is not in my PATHEXT. So I get the following results:

which.pl which.pl  => which.pl not found in PATH
which.pl which     => d:\...\which.exe   d:\...\which.com
which.pl which.exe => which.exe not found in PATH

I wouldn't have expected which.pl to be listed by "which.pl which", but I would expect it to be listed by "which.pl which.pl". And I would expect "which.pl which.exe" to find my which.exe, even though I did specify the extension.

Perhaps you would prefer that it not work as I suggest, but I think that my suggestions would make it work more like Windows does. And for a which.pl that seems to be trying to work well in a Windows environment... it would seem to me that it would be a good idea to work more like Windows does.

--
Glenn -- http://nevcal.com/
===========================
Like almost everyone, I receive a lot of spam every day, much of it
offering to help me get out of debt or get rich quick.  It's ridiculous.
-- Bill Gates

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to