2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/tailog/ext/bash.rb', line 2
def self.evaluate_string script
output = []
Open3.popen3("bash -x -e") do |stdin, stdout, stderr, wait_thr|
Thread.new do until (line = stdout.gets).nil? do output << [ :stdout, line ] end end
Thread.new do until (line = stderr.gets).nil? do output << [ :stderr, line ] end end
stdin.puts script
stdin.puts "exit"
wait_thr.join
end
output.map do |key, line|
if key == :stderr && line =~ /^\+ (.*)/
[:stdin, line]
else
[key, line]
end
end
end
|