diff --git a/lib/vagrant/plugin/remote/communicator.rb b/lib/vagrant/plugin/remote/communicator.rb index fd30396aa..17d0e57b5 100644 --- a/lib/vagrant/plugin/remote/communicator.rb +++ b/lib/vagrant/plugin/remote/communicator.rb @@ -48,9 +48,12 @@ module Vagrant res.exit_code end - def sudo(cmd, opts=nil) + def sudo(cmd, opts=nil, &block) @logger.debug("remote communicator, executing (privileged) command") - @client.privileged_execute(@machine, cmd, opts) + res = @client.privileged_execute(@machine, cmd, opts) + yield :stdout, res.stdout if block_given? + yield :stderr, res.stderr if block_given? + res.exit_code end def test(cmd, opts=nil) diff --git a/plugins/commands/serve/client/communicator.rb b/plugins/commands/serve/client/communicator.rb index 0da66bb22..03715ce78 100644 --- a/plugins/commands/serve/client/communicator.rb +++ b/plugins/commands/serve/client/communicator.rb @@ -143,7 +143,7 @@ module VagrantPlugins @logger.debug("privleged excuting") res = client.privileged_execute(req) @logger.debug("privleged excution result: #{res}") - res.exit_code + res end # @param [Vagrant::Machine] diff --git a/plugins/commands/serve/service/communicator_service.rb b/plugins/commands/serve/service/communicator_service.rb index 0c61cc314..8ff34613c 100644 --- a/plugins/commands/serve/service/communicator_service.rb +++ b/plugins/commands/serve/service/communicator_service.rb @@ -256,11 +256,15 @@ module VagrantPlugins plugin = Vagrant.plugin("2").manager.communicators[plugin_name.to_s.to_sym] communicator = plugin.new(machine) opts.transform_keys!(&:to_sym) - exit_code = communicator.sudo(cmd.command, opts) - logger.debug("command exit code: #{exit_code}") + output = {stdout: '', stderr: ''} + exit_code = communicator.sudo(cmd.command, opts) { + |type, data| output[type] << data if output[type] + } SDK::Communicator::ExecuteResp.new( - exit_code: exit_code + exit_code: exit_code, + stdout: output[:stdout], + stderr: output[:stderr] ) end end