【问题标题】:How to search an executable in $PATH in Ruby [duplicate]如何在 Ruby 中搜索 $PATH 中的可执行文件 [重复]
【发布时间】:2013-06-20 08:07:53
【问题描述】:

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

我知道我能做到:

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

但它有红宝石的方式吗?比如:

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

【问题讨论】:

  • 阅读答案 - 我认为这没有内置方法?

标签: ruby


【解决方案1】:

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

【讨论】:

  • 想知道为什么它没有记录...无论如何谢谢。也许坚持手动搜索 ENV['PATH']
  • 无证,因为它是给internal use only的。
猜你喜欢
  • 1970-01-01
  • 2018-11-22
  • 1970-01-01
  • 2020-11-04
  • 2010-12-11
  • 2017-03-26
  • 2021-08-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多