Class: VagrantPlugins::ProviderZone::Executor::Exec

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-zone/executor.rb

Overview

This class is used to execute commands as subprocess.

Instance Method Summary collapse

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vagrant-zone/executor.rb', line 12

def execute(exit_code, *cmd, **opts, &block)
	# Append in the options for subprocess
	cmd << { notify: [: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")

	if result.exit_code != 0 || interrupted
		raise Errors::ExecuteError
	end

	result.stdout[0..-2]
end