27
28
29
30
31
32
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/trace-runner.rb', line 27
def run(command, start, lines, statusIndicator = false)
audit = Audit.new @raw
log = Logger.new(Canzea::config[:logging_root] + '/plans.log')
log.info("HANDLING: " + command)
l = command
audit.start( "#{lines + 1 }", l.chomp)
t1 = Time.now
workingDir = Canzea::config[:pwd]
pputs "Executing [#{workingDir}] #{l}"
Dir.chdir(workingDir){
Open3.popen3(ENV, l) {|stdin, stdout, stderr, wait_thr|
pid = wait_thr.pid
log_w = StringIO.new
stillOpen = [stdout, stderr]
while !stillOpen.empty?
fhs = select(stillOpen, nil, nil, nil)
handleIO(stillOpen, fhs[0], stdout, log_w)
handleIO(stillOpen, fhs[0], stderr, log_w)
end
exit_status = wait_thr.value
log_w.close_write
t2 = Time.now
msecs = time_diff_milli t1, t2
output = log_w.string
output.scan(/.{1,80}/).each do | line |
log.info("STDOUT: #{line}")
end
log.info("Exit Status = #{exit_status}")
log.info("Completed in (ms) : #{msecs}")
pputs "Exit Status = #{exit_status}"
output.split(/\n/).each do | line |
pputs "#{line}"
end
audit.complete("#{lines + 1}", l.chomp, exit_status.exitstatus, msecs, output)
if (statusIndicator)
audit.status("#{lines + 1}", l.chomp, exit_status.exitstatus, msecs, output)
end
if (@raw)
puts output
end
if exit_status.exitstatus != 0
abort()
end
}
}
lines += 1
return lines
end
|