Class: VagrantPlugins::ProviderZone::Executor::Exec
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderZone::Executor::Exec
- Defined in:
- lib/vagrant-zones/executor.rb
Overview
This class is used to execute commands as subprocess.
Instance Method Summary collapse
-
#execute(exit_code, *cmd, **_opts, &block) ⇒ Object
When we need the command’s exit code we should set parameter exit_code to true, otherwise this method will return executed command’s stdout.
Instance Method Details
#execute(exit_code, *cmd, **_opts, &block) ⇒ Object
When we need the command’s exit code we should set parameter exit_code to true, otherwise this method will return executed command’s stdout
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vagrant-zones/executor.rb', line 14 def execute(exit_code, *cmd, **_opts, &block) # Append in the options for subprocess cmd << { notify: %i[stdout stderr] } cmd.unshift('sh', '-c') interrupted = false # Lambda to change interrupted to true int_callback = -> { interrupted = true } result = ::Vagrant::Util::Busy.busy(int_callback) do ::Vagrant::Util::Subprocess.execute(*cmd, &block) end return result.exit_code if exit_code result.stderr.gsub!("\r\n", "\n") result.stdout.gsub!("\r\n", "\n") puts "Command Failed: #{cmd}" if result.exit_code != 0 || interrupted puts "Exit Results: #{result.stderr}" if result.exit_code != 0 || interrupted raise Errors::ExecuteError if result.exit_code != 0 || interrupted result.stdout[0..-2] end |