什么';从Ruby检查系统上是否存在命令行工具的最优雅的方法是什么?
为了便于参考,这里讨论了Bash等价物: 我一直在做类似的事情什么';从Ruby检查系统上是否存在命令行工具的最优雅的方法是什么?,ruby,Ruby,为了便于参考,这里讨论了Bash等价物: 我一直在做类似的事情 if `which commandname` =~ /commandname/ # do stuff end 但是我想知道是否有更干净的东西。也许if File.executable?(`which commandname`)只要调用该命令,并捕获在该命令不存在时引发的异常。 system("ls") #=> true system("ls wrong params") #=> false system("ls
if `which commandname` =~ /commandname/
# do stuff
end
但是我想知道是否有更干净的东西。也许
if File.executable?(`which commandname`)
只要调用该命令,并捕获在该命令不存在时引发的异常。
system("ls")
#=> true
system("ls wrong params")
#=> false
system("lss")
#=> nil
if system("your cmd")
puts "yey!"
else
puts "oups"
end