inspec/lib/vulcano/backend/local.rb
Dominik Richter 13bc7f4015 move linux file handling to separate class
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
2015-09-22 02:15:40 +02:00

48 lines
807 B
Ruby

# encoding: utf-8
if IO.respond_to?(:popen4)
def open4(*args)
IO.popen4(*args)
end
else
require 'open4'
end
module Vulcano::Backends
class Local < Vulcano.backend(1)
name 'local'
def initialize(conf)
@conf = conf
@files = {}
end
def file(path)
@files[path] ||= LinuxFile.new(self, path)
end
def run_command(cmd)
Command.new(cmd)
end
def to_s
'Local Command Runner'
end
class Command
attr_reader :stdout, :stderr, :exit_status
def initialize(cmd)
@cmd = cmd
pid, stdin, stdout, stderr = open4(cmd)
stdin.close
_, status = Process.waitpid2 pid
@stdout = stdout.read
@stderr = stderr.read
@exit_status = status.exitstatus
end
end
end
end