From 6bf01965de3e9565273573db1fe6c27be905f19d Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 4 Apr 2018 11:17:31 -0700 Subject: [PATCH] Fix run command for windows hosts --- lib/vagrant/plugin/v2/trigger.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/plugin/v2/trigger.rb b/lib/vagrant/plugin/v2/trigger.rb index 5c9e6b242..a42887f6b 100644 --- a/lib/vagrant/plugin/v2/trigger.rb +++ b/lib/vagrant/plugin/v2/trigger.rb @@ -4,6 +4,8 @@ require 'shellwords' require Vagrant.source_root.join("plugins/provisioners/shell/provisioner") require "vagrant/util/subprocess" +require "vagrant/util/platform" +require "vagrant/util/powershell" module Vagrant module Plugin @@ -157,15 +159,27 @@ module Vagrant def run(config, on_error) if !config.inline.nil? cmd = Shellwords.split(config.inline) + + if Vagrant::Util::Platform.windows? + powershell_exe = Vagrant::Util::PowerShell.executable + cmd = Shellwords.split("#{powershell_exe} #{config.powershell_args} '#{cmd.join(' ')}'") + end + @machine.ui.detail(I18n.t("vagrant.trigger.run.inline")) else cmd = File.expand_path(config.path, @env.root_path) - FileUtils.chmod("+x", cmd) # TODO: what about windows + FileUtils.chmod("+x", cmd) + + if Vagrant::Util::Platform.windows? + powershell_exe = Vagrant::Util::PowerShell.executable + cmd = Shellwords.split("#{powershell_exe} #{config.powershell_args} #{cmd}") + end + @machine.ui.detail(I18n.t("vagrant.trigger.run.script", path: config.path)) end + begin - # TODO: should we check config or command for sudo? And if so, WARN the user? result = Vagrant::Util::Subprocess.execute(*cmd, :notify => [:stdout, :stderr]) do |type,data| options = {} case type @@ -220,7 +234,7 @@ module Vagrant raise e else @logger.debug("Trigger run encountered an error. Continuing on anyway...") - @machine.ui.error(I18n.t("vagrant.errors.triggers.run_fail")) + @machine.ui.error(I18n.t("vagrant.errors.triggers_run_fail")) @machine.ui.error(e.message) end end