Sha256: 88d57f429d0bafaec0f7d63049d3e5938e2d81790a6accae69ad11989c1eca93

Contents?: true

Size: 579 Bytes

Versions: 21

Compression:

Stored size: 579 Bytes

Contents

# frozen_string_literal: true
require "rbconfig"

module EnvUtil
  def find_executable(cmd, *args)
    exts = RbConfig::CONFIG["EXECUTABLE_EXTS"].split | [RbConfig::CONFIG["EXEEXT"]]
    ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
      next if path.empty?
      path = File.join(path, cmd)
      exts.each do |ext|
        cmdline = [path + ext, *args]
        begin
          return cmdline if yield(IO.popen(cmdline, "r", err: [:child, :out], &:read))
        rescue
          next
        end
      end
    end
    nil
  end
  module_function :find_executable
end

Version data entries

21 entries across 20 versions & 6 rubygems

Version Path
test-unit-ruby-core-1.0.6 lib/find_executable.rb
test-unit-ruby-core-1.0.5 lib/find_executable.rb
test-unit-ruby-core-1.0.4 lib/find_executable.rb
test-unit-ruby-core-1.0.3 lib/find_executable.rb
test-unit-ruby-core-1.0.2 lib/find_executable.rb
test-unit-ruby-core-1.0.1 lib/find_executable.rb
test-unit-ruby-core-1.0.0 lib/find_executable.rb
did_you_mean-1.6.3 test/lib/find_executable.rb
did_you_mean-1.6.2 test/lib/find_executable.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/json-2.5.1/tests/lib/find_executable.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/json-2.5.1/tests/lib/find_executable.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/json-2.5.1/tests/lib/find_executable.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/json-2.5.1/tests/lib/find_executable.rb
cloudsmith-api-0.57.1 vendor/bundle/ruby/2.6.0/gems/json-2.5.1/tests/lib/find_executable.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/json-2.5.1/tests/lib/find_executable.rb
json_pure-2.5.1 tests/lib/find_executable.rb
json-2.5.1 tests/lib/find_executable.rb
json-2.5.1-java tests/lib/find_executable.rb
json-2.5.0-java tests/lib/find_executable.rb
json_pure-2.5.0 tests/lib/find_executable.rb