def self.track_output(command, port = nil)
ensure_puppetserver_running(port)
successful = true
debug('#' * 80, nil ,'')
debug("Starting #{command}\n")
start_time = Time.now
linecount = 0
col = ['green','red','yellow','blue','magenta','cyan']
if @track
info("Track => ", 'cyan')
begin
::PTY.spawn("#{command}") do |read, write, pid|
begin
read.each do |line|
print ("#".send(col.first)) unless @verbose
col.rotate!
debug(line)
linecount += 1
end
rescue Errno::EIO
end
end
rescue PTY::ChildExited => e
warn("#{command} exited unexpectedly:\n\t#{e.message}")
successful = false
rescue
debug('Running without a PTY!')
output = %x{#{command}}
debug(output)
linecount = output.split("\n").length
successful = false if $? != 0
end
else
info('Running, please wait ... ')
$stdout.flush
show_wait_spinner {
output = %x{#{command}}
}
debug(output)
linecount = output.split("\n").length
successful = false if $? != 0
end
puts
debug("\n#{command} - Done!")
end_time = Time.now
debug("Duration of Puppet run: #{end_time - start_time} seconds")
return successful ? linecount : -1
end