33: def self.exec(code, interpreter = nil)
34: Facter.warnonce "The interpreter parameter to 'exec' is deprecated and will be removed in a future version." if interpreter
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46: if have_which and !Facter::Util::Config.is_windows?
47: path = nil
48: binary = code.split.first
49: if code =~ /^\//
50: path = binary
51: else
52: path = %x{which #{binary} 2>/dev/null}.chomp
53:
54: return nil if path == "" or path.match(/Command not found\./)
55: end
56:
57: return nil unless FileTest.exists?(path)
58: end
59:
60: out = nil
61:
62: begin
63: out = %x{#{code}}.chomp
64: rescue Errno::ENOENT => detail
65:
66: return nil
67: rescue => detail
68: $stderr.puts detail
69: return nil
70: end
71:
72: if out == ""
73: return nil
74: else
75: return out
76: end
77: end