<分区>
是否有用于在 (Linux) 系统路径中搜索可执行文件的 ruby 函数?
我知道我可以做到:
path = `which ls` # found if $?.exitstatus == 0
但是它有 ruby 的方式吗?像这样的东西:
find_in_path('ls') # => '/bin/ls'
标签 ruby
<分区>
是否有用于在 (Linux) 系统路径中搜索可执行文件的 ruby 函数?
我知道我可以做到:
path = `which ls` # found if $?.exitstatus == 0
但是它有 ruby 的方式吗?像这样的东西:
find_in_path('ls') # => '/bin/ls'
最佳答案
>> 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. 查找中使用 %?
ruby - 将所有 xpath 结果收集到 ruby 中的数组中
ruby - 使用 sinatra,我如何从 3 个单独的输入框构造一个正确的 DateTime 值?