33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/buildaemon.rb', line 33
def self.Execute(command)
timestamp = DateTime.now.strftime("%y/%m/%d %H:%M:%S")
puts Terminal.ToColorString(Terminal::Ground::Foreground + Terminal::Color::Green, "[#{timestamp}] $ #{command}")
Open3.popen3(command){|i, o, e, w|
i.close
threads = [
Thread.new{
while (line = o.gets) do
STDOUT.puts line.toutf8
end
},
Thread.new{
while (line = e.gets) do
STDERR.puts line.toutf8
end
}
].each{|thread| thread.join}
status = w.value
exitCode = status.exitstatus.nil? ? status.termsig : status.exitstatus
if block_given?
yield(status)
elsif exitCode != 0
exit(exitCode)
end
}
end
|