diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb index 8a924d6..2133ce3 100644 --- a/lib/execjs/external_runtime.rb +++ b/lib/execjs/external_runtime.rb @@ -120,20 +120,25 @@ def binary @binary ||= which(@command) end - def locate_executable(cmd) - if ExecJS.windows? && File.extname(cmd) == "" - cmd << ".exe" - end - - if File.executable? cmd - cmd - else - path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |p| - full_path = File.join(p, cmd) - File.executable?(full_path) && File.file?(full_path) + def locate_executable(command) + commands = Array(command) + if ExecJS.windows? && File.extname(command) == "" + ENV['PATHEXT'].split(File::PATH_SEPARATOR).each { |p| + commands << (command + p) } - path && File.expand_path(cmd, path) end + + commands.find { |cmd| + if File.executable? cmd + cmd + else + path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |p| + full_path = File.join(p, cmd) + File.executable?(full_path) && File.file?(full_path) + } + path && File.expand_path(cmd, path) + end + } end protected