lib/ztk/command.rb in ztk-1.5.0 vs lib/ztk/command.rb in ztk-1.5.1

- old
+ new

@@ -113,13 +113,12 @@ direct_log(:info) { log_header("STARTED") } begin Timeout.timeout(options.timeout) do loop do - pipes = IO.select(reader_writer_map.keys, [], reader_writer_map.keys).first - pipes.each do |pipe| - data = pipe.read + reader_writer_map.keys.each do |pipe| + data = (pipe.readpartial(1024) rescue nil) next if (data.nil? || data.empty?) case reader_writer_key[pipe] when :stdout then if !stdout_header @@ -141,10 +140,11 @@ end output += data end break if reader_writer_map.keys.all?{ |reader| reader.eof? } + sleep(0.1) end end rescue Timeout::Error => e direct_log(:fatal) { log_header("TIMEOUT") } log_and_raise(CommandError, "Process timed out after #{options.timeout} seconds!") @@ -182,11 +182,11 @@ private # Returns a string in the format of "user@hostname" for the current # shell. def tag - @@hostname ||= %x(hostname).chomp - "#{ENV['USER']}@#{@hostname}" + @@hostname ||= %x(hostname).split('.').first.strip + "#{ENV['USER']}@#{@@hostname}" end # Formats a header suitable for writing to the direct logger when logging # sessions. def log_header(what)