Get stdout and stderr from command
This commit is contained in:
parent
c63e7936b2
commit
8e85561f61
@ -40,9 +40,12 @@ module Vagrant
|
||||
@client.upload(@machine, from, to)
|
||||
end
|
||||
|
||||
def execute(cmd, opts=nil)
|
||||
def execute(cmd, opts=nil, &block)
|
||||
@logger.debug("remote communicator, executing command")
|
||||
@client.execute(@machine, cmd, opts)
|
||||
res = @client.execute(@machine, cmd, opts)
|
||||
yield :stdout, res.stdout if block_given?
|
||||
yield :stderr, res.stderr if block_given?
|
||||
res.exit_code
|
||||
end
|
||||
|
||||
def sudo(cmd, opts=nil)
|
||||
|
||||
@ -131,7 +131,7 @@ module VagrantPlugins
|
||||
@logger.debug("excuting")
|
||||
res = client.execute(req)
|
||||
@logger.debug("excution result: #{res}")
|
||||
res.exit_code
|
||||
res
|
||||
end
|
||||
|
||||
# @param [Vagrant::Machine]
|
||||
|
||||
@ -208,11 +208,17 @@ 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.execute(cmd.command, opts)
|
||||
output = {stdout: '', stderr: ''}
|
||||
exit_code = communicator.execute(cmd.command, opts) {
|
||||
|type, data| output[type] << data if output[type]
|
||||
}
|
||||
logger.debug("command exit code: #{exit_code}")
|
||||
logger.debug("command output: #{output}")
|
||||
|
||||
SDK::Communicator::ExecuteResp.new(
|
||||
exit_code: exit_code
|
||||
exit_code: exit_code,
|
||||
stdout: output[:stdout],
|
||||
stderr: output[:stderr]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user