Class: HuginnAgent::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/huginn_agent/helper.rb

Class Method Summary collapse

Class Method Details

.exec(command) ⇒ Object



22
23
24
25
# File 'lib/huginn_agent/helper.rb', line 22

def self.exec(command)
  print "\n"
  [system(ENV, command) == true ? 0 : 1, '']
end

.open3(command) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/huginn_agent/helper.rb', line 5

def self.open3(command)
  output = ""

  status = Open3.popen3(ENV, "#{command} 2>&1") do |stdin, stdout, _stderr, wait_thr|
    stdin.close

    until stdout.eof do
      next unless IO.select([stdout])
      output << stdout.read_nonblock(1024)
    end
    wait_thr.value
  end
  [status.exitstatus, output]
rescue IOError => e
  return [1, "#{e} #{e.message}"]
end