English 中文(简体)
可通过垃圾档案获得可起诉(文字、殴打、 cm)
原标题:Confirm existance of executable (script, bat, cmd, exe) via a ruby file

使用废 rub档案(或任何假肢设施) 我需要发现,如果执行我的文字的使用者能够执行某些弹道。 尤其是g++等。 如果存在一些++.bat、g++.exe或仅是g++(etc),那么希望系统独立,但只要其走上这条道路,在用户系统中可以执行,它就应该说是。

例:如果用户对档案没有可执行的版本,而且档案有可执行的版本,那么就应当说,对单轴系统没有延伸版本,对窗户系统的“是”,而“是”。 由于用户只能执行该版本的档案。

其目的是使文字能够自行配置(尽可能多)。

关于我如何做到这一点的任何建议?

最佳回答

一种快速和不附带的方式,就是试图通过<编码>系统执行g++。 指挥和检查返回法,例如:

def gpp_exists
  return system("g++ --version")
end

你们必须做一些trick,以避免在ole子上获得不想要的产出(例如,根据正确的非洲顾问团,重新引导下台/台阶),但是,它不会太坏。

问题回答

http://ruby-doc.org/french/sc/presidency.html ENV[ PATH] > 查询目录的可执行性(至少在*nix――有人可以确认为Windows?) two两条,有魔力,你应该有解决办法。

Edit:

irb(main):001:0> ENV[ PATH ].split( : ).collect {|d| Dir.entries d if Dir.exists? d}.flatten.include?  adduser 
=> true
irb(main):002:0> ENV[ PATH ].split( : ).collect {|d| Dir.entries d if Dir.exists? d}.flatten.include?  foo 
=> false

i 有时需要类似的东西(在路上可以执行),使用系统指挥,但检查错误的返回代码。 根据这一标准,得出了不ix(127 = 未找到的档案)

    def checkinstalled(program)
      stdop=system(program)
      result=$?
      exit_code=result.exitstatus 
      return !exit_code.eql?(127)
    end

但是,对窗口说几句。





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签