Get stdout and stderr from privledged execute

This commit is contained in:
sophia 2021-12-20 12:01:44 -06:00 committed by Paul Hinze
parent 88e1e5c1a7
commit 7a75ed6cbb
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 13 additions and 6 deletions

View File

@ -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)

View File

@ -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]

View File

@ -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