Skip to content

Instantly share code, notes, and snippets.

@vertis
Created June 17, 2011 00:02
Show Gist options
  • Select an option

  • Save vertis/1030613 to your computer and use it in GitHub Desktop.

Select an option

Save vertis/1030613 to your computer and use it in GitHub Desktop.
begin
descriptors = []
files = []
ARGV.each do |filename|
io = IO.sysopen(filename, 'r')
descriptors << io
i = IO.open(io)
i.seek(0, IO::SEEK_END) # TODO: go back a few lines so we have context
files << i
end
loop do
while files.map(&:eof).inject(false) {|result, it| result ||= it; result }
sleep 0.2
end
files.each do |file|
until file.eof?
$stdout.print file.gets
end
$stdout.flush
end
end
ensure
descriptors.each do |desc|
begin
IO.open(desc) { |fd| fd.close }
rescue Errno::EBADF
$stderr.puts "Errno::EBADF: Trying to close bad file descriptor"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment