Class: SpecInfra::Backend::Exec

Inherits:
Object
  • Object
show all
Defined in:
lib/monkeypatch/serverspec/backend/exec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chroot_dirObject

Returns the value of attribute chroot_dir


56
57
58
# File 'lib/monkeypatch/serverspec/backend/exec.rb', line 56

def chroot_dir
  @chroot_dir
end

Instance Method Details

#run_command(cmd, opts = {}) ⇒ Object

ORIGINAL def run_command(cmd, opts={})

cmd = build_command(cmd)
cmd = add_pre_command(cmd)
stdout = run_with_no_ruby_environment do
  `#{build_command(cmd)} 2>&1`
end
# In ruby 1.9, it is possible to use Open3.capture3, but not in 1.8
# stdout, stderr, status = Open3.capture3(cmd)

if @example
  @example.[:command] = cmd
  @example.[:stdout]  = stdout
end

CommandResult.new :stdout => stdout, :exit_status => $?.exitstatus

end /ORIGINAL


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/monkeypatch/serverspec/backend/exec.rb', line 32

def run_command(cmd, opts={})
  cmd = build_command(cmd)
  cmd = add_pre_command(cmd)
  # In ruby 1.9, it is possible to use Open3.capture3, but not in 1.8
  # stdout, stderr, status = Open3.capture3(cmd)

  if use_chroot?
    chroot_stdout = `#{chroot_cmd(cmd)} 2>&1`

    stdout = get_stdout(chroot_stdout)
    exit_status = get_exit_status(chroot_stdout)
  else
    stdout = run_with_no_ruby_environment { `#{cmd} 2>&1` }
    exit_status = $?.exitstatus
  end

  if @example
    @example.[:command] = cmd
    @example.[:stdout]  = stdout
  end

  CommandResult.new :stdout => stdout, :exit_status => exit_status
end