Question

Ce que je suis en train de faire est de passer un argument pour une option dans un script Ruby qui sera une commande unix. La commande peut (probablement) impliquent greps, tuyaux et beaucoup d'autres choses possibles. Essentiellement, ce que je me demande est, une option peut GetOptLong être configuré pour accepter un caractère comme argument. Pour ce que ça vaut, je ne peux pas utiliser OptionParser, et probablement pas non plus plouc (ou quelque chose comme ça).

Merci, -Rob

Était-ce utile?

La solution

Pretty sure you can just pass in your unix commands as a string and execute them from within your script.. so something like:

#getoptlong.rb

require 'getoptlong'

opts = GetoptLong.new(
  [ '--unix', GetoptLong::OPTIONAL_ARGUMENT ]
)

opts.each do |opt, arg|
  case opt
    when '--unix'
      puts `#{arg}`
  end
end

and execute the script with something like:

ruby getOptLong.rb --unix "netstat -an | grep '61613'"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top