Class: RDialogy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rdialogy/base.rb

Class Method Summary collapse

Class Method Details

.run(options = {}, std_err = false) ⇒ Object

assembles the arguments for dialog and executes them, if std_err is true STDERR is captured and returned, optionally formatted by supplied block.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rdialogy/base.rb', line 10

def self.run(options={}, std_err = false)
  cmd = dialog_string options

  if std_err
    begin
      tmp = Tempfile.new('tmp')
      cmd += ' 2> ' + tmp.path
    
      system cmd

      output = String.new
      while true
        output += tmp.readline
      end
    rescue EOFError
      if block_given?
        return yield output
      else
        return output
      end
    ensure
      tmp.close
    end
  else
    system cmd
  end
end