Fix issue where we may not get the full output in a subprocess

This commit is contained in:
Mitchell Hashimoto 2011-12-21 14:28:43 -08:00
parent d5981978a1
commit 8eb1770b9d
1 changed files with 26 additions and 19 deletions

View File

@ -65,27 +65,34 @@ module Vagrant
# Check the readers to see if they're ready # Check the readers to see if they're ready
if !readers.empty? if !readers.empty?
begin readers.each do |r|
readers.each do |r| data = ""
data = r.read_nonblock(1024) while true
io_name = r == stdout ? :stdout : :stderr begin
@logger.debug(data) data << r.read_nonblock(1024)
rescue IO::WaitReadable
if io_name == :stderr && io_data[r] == "" && data =~ /Errno::ENOENT/ # This just means the IO wasn't actually ready and we
# This is how we detect that a process failed to start on # should wait some more. No problem! Just pass on through...
# Linux. Hacky, but it works fairly well. rescue EOFError
raise ProcessFailedToStart # Process exited, most likely. We're done here.
break
end end
io_data[r] += data
yield io_name, data if block_given?
end end
rescue IO::WaitReadable
# This just means the IO wasn't actually ready and we # We don't need to do anything if the data is empty
# should wait some more. No problem! Just pass on through... next if data.empty?
rescue EOFError
# Process exited, most likely. We're done here. io_name = r == stdout ? :stdout : :stderr
break @logger.debug(data)
if io_name == :stderr && io_data[r] == "" && data =~ /Errno::ENOENT/
# This is how we detect that a process failed to start on
# Linux. Hacky, but it works fairly well.
raise ProcessFailedToStart
end
io_data[r] += data
yield io_name, data if block_given?
end end
end end