def self.track_output(command, port = nil)
ensure_running(port)
successful = true
@logfile.print '#' * 80
@logfile.puts("\nStarting #{command}\n")
start_time = Time.now
linecount = 0
if @track
print 'Track => '
begin
::PTY.spawn("#{command}") do |read, write, pid|
begin
read.each do |line|
print '#'
@logfile.puts(line)
linecount += 1
end
rescue Errno::EIO
end
end
rescue PTY::ChildExited => e
print '!!!'
@logfile.puts("Child exited unexpectedly:\n\t#{e.message}")
successful = false
rescue
@logfile.puts "Running without a PTY!"
output = %x{#{command}}
@logfile.puts output
linecount = output.split("\n").length
successful = false if $? != 0
end
else
print "Running, please wait ... "
$stdout.flush
output = %x{#{command}}
@logfile.puts output
linecount = output.split("\n").length
successful = false if $? != 0
end
puts " Done!"
@logfile.puts("\n#{command} - Done!")
end_time = Time.now
puts "Duration of Puppet run: #{end_time - start_time} seconds" if @verbose
@logfile.puts("Duration of Puppet run: #{end_time - start_time} seconds")
return successful ? linecount : -1
end