diff --git a/plugins/pushes/local-exec/push.rb b/plugins/pushes/local-exec/push.rb index 718b1ab04..d4bc75176 100644 --- a/plugins/pushes/local-exec/push.rb +++ b/plugins/pushes/local-exec/push.rb @@ -39,8 +39,33 @@ module VagrantPlugins # Execute the script, raising an exception if it fails. def execute!(*cmd) + if Vagrant::Util::Platform.windows? + execute_subprocess!(*cmd) + else + execute_exec!(*cmd) + end + end + + private + + # Run the command as exec (unix). + def execute_exec!(*cmd) Vagrant::Util::SafeExec.exec(cmd[0], *cmd[1..-1]) end + + # Run the command as a subprocess (windows). + def execute_subprocess!(*cmd) + cmd = cmd.dup << { notify: [:stdout, :stderr] } + result = Vagrant::Util::Subprocess.execute(*cmd) do |type, data| + if type == :stdout + @env.ui.info(data, new_line: false) + elsif type == :stderr + @env.ui.warn(data, new_line: false) + end + end + + Kernel.exit(result.exit_code) + end end end end diff --git a/test/unit/plugins/pushes/local-exec/push_test.rb b/test/unit/plugins/pushes/local-exec/push_test.rb index 1efdfa3b1..e7c04060d 100644 --- a/test/unit/plugins/pushes/local-exec/push_test.rb +++ b/test/unit/plugins/pushes/local-exec/push_test.rb @@ -93,9 +93,19 @@ describe VagrantPlugins::LocalExecPush::Push do end describe "#execute!" do - it "safe execs" do + it "uses exec on unix" do + allow(Vagrant::Util::Platform).to receive(:windows?).and_return(false) expect(Vagrant::Util::SafeExec).to receive(:exec) expect { subject.execute! }.to_not raise_error end + + it "uses subprocess on windows" do + allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true) + result = double("result", exit_code: 0) + expect(Vagrant::Util::Subprocess).to receive(:execute).and_return(result) + expect { subject.execute! }.to raise_error { |e| + expect(e).to be_a(SystemExit) + } + end end end