# File lib/facter/util/resolution.rb, line 33
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:     # Try to guess whether the specified code can be executed by looking at the
37:     # first word. If it cannot be found on the PATH defer on resolving the fact
38:     # by returning nil.
39:     # This only fails on shell built-ins, most of which are masked by stuff in
40:     # /bin or of dubious value anyways. In the worst case, "sh -c 'builtin'" can
41:     # be used to work around this limitation
42:     #
43:     # Windows' %x{} throws Errno::ENOENT when the command is not found, so we
44:     # can skip the check there. This is good, since builtins cannot be found
45:     # elsewhere.
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:         # we don't have the binary necessary
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:       # command not found on Windows
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