Class: ChupaText::ExternalCommand
- Inherits:
-
Object
- Object
- ChupaText::ExternalCommand
- Defined in:
- lib/chupa-text/external-command.rb
Defined Under Namespace
Classes: SpawnLimitOptions
Instance Method Summary collapse
- #exist? ⇒ Boolean
-
#initialize(command) ⇒ ExternalCommand
constructor
A new instance of ExternalCommand.
- #run(*arguments) ⇒ Object
Constructor Details
#initialize(command) ⇒ ExternalCommand
Returns a new instance of ExternalCommand.
23 24 25 |
# File 'lib/chupa-text/external-command.rb', line 23 def initialize(command) @command = Pathname.new(command) end |
Instance Method Details
#exist? ⇒ Boolean
42 43 44 45 46 47 48 49 50 |
# File 'lib/chupa-text/external-command.rb', line 42 def exist? if @command.absolute? @command.file? and @command.executable? else (ENV['PATH'] || "").split(File::PATH_SEPARATOR).any? do |path| (Pathname.new(path) + @command)..exist? end end end |
#run(*arguments) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/chupa-text/external-command.rb', line 27 def run(*arguments) if arguments.last.is_a?(Hash) = arguments.pop else = {} end = [:spawn_options] || {} pid = spawn([:env] || {}, @command.to_s, *arguments, .merge()) pid, status = Process.waitpid2(pid) status.success? end |