mirror of
https://github.com/inspec/inspec
synced 2024-12-24 03:53:15 +00:00
275039dead
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
47 lines
806 B
Ruby
47 lines
806 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
|