ruby - 如何在 Ruby 中搜索 $PATH 中的可执行文件

标签 ruby

<分区>

是否有用于在 (Linux) 系统路径中搜索可执行文件的 ruby​​ 函数?

我知道我可以做到:

path = `which ls` # found if $?.exitstatus == 0

但是它有 ruby 的方式吗?像这样的东西:

find_in_path('ls') # => '/bin/ls'

最佳答案

find_executable

>> require 'mkmf'
=> true
>> find_executable 'ls'
checking for ls... yes
=> "/bin/ls"
>> find_executable 'no-such-command'
checking for no-such-command... no
=> nil

关于ruby - 如何在 Ruby 中搜索 $PATH 中的可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17208423/

相关文章:

ruby-on-rails - Rails 如何从字符串地址获取经纬度并将其放在谷歌地图上?

ruby - UBUNTU 14.04 (x86_64) 上的 rbenv : BUILD FAILED when Install Ruby 2. 2.3

sql - 如何在 :conditions argument to ActiveRecord. 查找中使用 %?

java - 从 Ruby 的角度看 Java

ruby - 避免使用相同的用户名和密码多次登录

ruby - 将所有 xpath 结果收集到 ruby​​ 中的数组中

ruby - 调用关闭和 splats

ruby - 使用 sinatra,我如何从 3 个单独的输入框构造一个正确的 DateTime 值?

ruby - 获取 OpenSSL::SSL::SSLError:证书验证失败 - 具有最新 ca 包的事件

sql - 使用 created_at 选择记录范围