From e85095d1bfa44d4bab386ed7c5088a4ee34a309d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 5 Jan 2012 23:48:30 -0800 Subject: [PATCH] Subprocess uses readpartial on IO for Windows [GH-610] Windows doesn't support read_nonblock. --- lib/vagrant/util/subprocess.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/util/subprocess.rb b/lib/vagrant/util/subprocess.rb index 03bb23113..2f35d70ec 100644 --- a/lib/vagrant/util/subprocess.rb +++ b/lib/vagrant/util/subprocess.rb @@ -1,6 +1,8 @@ require 'childprocess' require 'log4r' +require 'vagrant/util/platform' + module Vagrant module Util # Execute a command in a subprocess, gathering the results and @@ -10,6 +12,9 @@ module Vagrant # from the subprocess in real time, by simply passing a block to # the execute method. class Subprocess + # The chunk size for reading from subprocess IO. + READ_CHUNK_SIZE = 4096 + # Convenience method for executing a method. def self.execute(*command, &block) new(*command).execute(&block) @@ -151,7 +156,15 @@ module Vagrant while true begin - data << io.read_nonblock(1024) + if Platform.windows? + # Windows doesn't support non-blocking reads on + # file descriptors or pipes so we have to get + # a bit more creative. + data << io.readpartial(READ_CHUNK_SIZE) + else + # Do a simple non-blocking read on the IO object + data << io.read_nonblock(READ_CHUNK_SIZE) + end rescue Exception => e # The catch-all rescue here is to support multiple Ruby versions, # since we use some Ruby 1.9 specific exceptions.