-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Ruby implementation for which
#315
Conversation
Thanks for your contributions! I'll find some time at the weekend to inspect your requests. |
The output "The System cannot find the path specified" appears for every rake run, but does not break the build if make is called I think this is a proper cross platform solution, that should be merged. |
I just rebased (just in case) and that previous Travis failure was due something else. |
12737f8
to
f4c7490
Compare
rebased again, why this haven't been merged? |
Please merge. |
Why iterate over the path and extensions rather than use a glob? |
@tduehr wouldn't work on Windows with their file extensions, e.g. notepad.exe, not notepad. |
|
Hm, for some reason I thought that approach had some issue, but perhaps I'm mistaken. Anyway, it's not like we need to hyper optimize for this little bit of functionality. I'm happy with whatever works. :) |
I'm don't really understand why glob would be preferable? I'm not sure if there would be any performance benefits. def which(name)
exts = ENV['PATHEXT'] ? '{' + ENV['PATHEXT'].split(';').join(',') + '}' : ''
paths = '{' + ENV['PATH'].split(File::PATH_SEPARATOR).join(',').gsub('\\', '/') + '}'
Dir.glob(paths + '/' + name + exts).each do |app|
return app if File.executable?(app)
end
nil
end In PATH there can be multiple executables with same name and some might not even be executable so we've to check all in correct order. |
I was wondering if there was a specific reason is all... Then i got to way over optimizing. I'll pull this when I get a chance to write something to use which normally then failover to this. |
In Windows there's no
/dev/null
and it causes error "The System cannot find the path specified". Also in Windows there's no nativewhich
and it works only because it's included in DevKit.This Ruby implementation should correctly work for all platforms.