in reply to Perl & NT

Another possibility is that NT doesn't have "which" unless you've added it using something like Cygwin or the MKS Toolkit. So there isn't enough information here to figure it out. We'd need to know:

<bl>

  • What shell you're using (CMD or something sh-like)
  • What the COMSPEC and SHELL variables are
  • What "which" is and whether it exists </bl> Anyway, if you just want a good which command, you might try this all-Perl solution (save as which.bat):

    @rem = '--*-Perl-*-- @echo off if "%OS%" == "Windows_NT" goto WinNT perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 goto endofperl :WinNT perl -x -S "%0" %* if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl if %errorlevel% == 9009 echo You do not have Perl in your PATH. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul goto endofperl @rem '; #!perl #line 15 # uses PATH and PATHEXT under NT my @path = split(';', $ENV{PATH}); my @pathext = split(';', $ENV{PATHEXT}); @pathext = qw(.com .exe .bat .cmd) if !@pathext; unshift(@pathext, ''); unshift(@path, '.'); my $all = 0; ARG: foreach my $arg (@ARGV) { if ($arg eq '-a') { $all = 1; next ARG; } foreach my $path (@path) { foreach my $ext (@pathext) { if (-f "$path\\$arg$ext") { print "$path\\$arg$ext\n"; next ARG if !$all; } } } } __END__ :endofperl