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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/maintainer/CommandRunner.rb', line 67
def _execute(command: nil, error:nil)
print_all = true
prefix ||= {}
output = []
if command.kind_of?(String)
cmd = command
else
cmd = command.command!
if command.requires_sudo!
self.execute_sudo(command: cmd)
return
end
end
cmd = command.command!.join(" ") if command.command!.kind_of?(Array)
Writer.write(message: "#{cmd}")
begin
status = Maintainer::MaintainerPty.spawn(cmd) do |command_stdout, command_stdin, pid|
command_stdout.each do |l|
line = l.strip
output << line
next unless print_all
prefix.each do |element|
line = element[:prefix] + line if element[:block] && element[:block].call(line)
end
Writer.write(message: "#{line}")
end
end
rescue => ex
status = ex.exit_status
output << ex.to_s
o = output.join("\n")
puts(o)
if error
error.call(o, nil)
else
raise ex
end
end
if status != 0
o = output.join("\n")
puts(o)
Writer.write(message: ("Exit status: #{status}"))
if error
error.call(o, status)
else
Writer.write(message: ("Exit status: #{status}"))
end
end
return output.join("\n")
end
|