From 3844a8e9f9efbedfa3c16905fb90806ad3c0ec01 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 14 Feb 2018 08:45:34 -0800 Subject: [PATCH] (#9056) Pass ruby block to capture stdout when determining PS version Prior to this commit, the function used to determine the version of Powershell would loop forever inside the Subprocess.execute function because the process would never exit. This commit fixes that by passing in a ruby block to capture the version from stdout instead of trying to capture it from the returned process when it exits. --- lib/vagrant/util/powershell.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/util/powershell.rb b/lib/vagrant/util/powershell.rb index 915ae4bb5..62a8bc472 100644 --- a/lib/vagrant/util/powershell.rb +++ b/lib/vagrant/util/powershell.rb @@ -11,6 +11,7 @@ module Vagrant class PowerShell # NOTE: Version checks are only on Major MINIMUM_REQUIRED_VERSION = 3 + LOGGER = Log4r::Logger.new("vagrant::util::powershell") # @return [Boolean] powershell executable available on PATH def self.available? @@ -85,8 +86,14 @@ module Vagrant "Write-Output $PSVersionTable.PSVersion.Major" ].flatten - r = Subprocess.execute(*command) - @_powershell_version = r.exit_code != 0 ? nil : r.stdout.chomp + version = nil + begin + r = Subprocess.execute(*command, notify: [:stdout, :stderr], timeout: 10) {|io_name,data| version = data} + rescue Vagrant::Util::Subprocess::TimeoutExceeded + LOGGER.debug("Timeout exceeded while attempting to determine version of Powershell.") + end + + @_powershell_version = version end @_powershell_version end