preload
Jan 11

I’m not sure if I picked this up from another website or not, but its been in my bag of tools almost as long as I’ve been programming in Ruby :)

#!c:\ruby\bin\ruby.exe -w

require 'exo/iswindows'

def which(pgm)
   @path = ENV['PATH'].split(/;/)
   @path.each { |cdir|
      cmd = cdir + "\\" + pgm
      if test(?s, cmd)
        return cdir
      end
    }
  return nil
end

if __FILE__ == $0
   aa = ARGV[0]
   if RUBY_PLATFORM.isWindows?
     if (! aa.index("."))
       aa += ".exe"
     end
   end

   rc = which(aa)
   if (rc)
     print rc
   else
     print "NOT FOUND in PATH=" + ENV['PATH']
   end
end

Put the which.rb file in the path somewhere and it works the same way as the unix command of the same name:
Continue reading »

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with: