Class: Facter::Core::Execution::Windows
  
  
  
  
  
    - Inherits:
 
    - 
      Base
      
        
          - Object
 
          
            - Base
 
          
            - Facter::Core::Execution::Windows
 
          
        
        show all
      
     
  
  
  
  
  
  
  
  
  
  
    - Defined in:
 
    - lib/facter/custom_facts/core/execution/windows.rb
 
  
  
 
Overview
  
    
      Constant Summary
      collapse
    
    
      
        - DEFAULT_COMMAND_EXTENSIONS =
          
        
 
        %w[.COM .EXE .BAT .CMD].freeze
 
      
        - ABSOLUTE_PATH_REGEX =
          
        
 
        /^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))/i.freeze 
      
        - DOUBLE_QUOTED_COMMAND =
          
        
 
        /\A"(.+?)"(?:\s+(.*))?/.freeze
 
      
    
  
  
  
  Constants inherited
     from Base
  Base::DEFAULT_EXECUTION_TIMEOUT, Base::STDERR_MESSAGE, Base::VALID_OPTIONS
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  Methods inherited from Base
  #execute_command, #initialize, #with_env
  
    Instance Method Details
    
      
  
  
    #absolute_path?(path)  ⇒ Boolean 
  
  
  
  
    
      
43
44
45 
     | 
    
      # File 'lib/facter/custom_facts/core/execution/windows.rb', line 43
def absolute_path?(path)
  !!(path =~ ABSOLUTE_PATH_REGEX)
end 
     | 
  
 
    
      
  
  
    #execute(command, options = {})  ⇒ Object 
  
  
  
  
    
      
68
69
70
71
72
73 
     | 
    
      # File 'lib/facter/custom_facts/core/execution/windows.rb', line 68
def execute(command, options = {})
  expand = options.fetch(:expand, true)
  raise ArgumentError.new, 'Unsupported argument on Windows expand with value false' unless expand
  super(command, options)
end
     | 
  
 
    
      
  
  
    #expand_command(command)  ⇒ Object 
  
  
  
  
    
      
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 
     | 
    
      # File 'lib/facter/custom_facts/core/execution/windows.rb', line 49
def expand_command(command)
  exe = nil
  args = nil
  if (match = command.match(DOUBLE_QUOTED_COMMAND))
    exe, args = match.captures
  else
    exe, args = command.split(/ /, 2)
  end
  return unless exe && (expanded = which(exe))
  expanded = expanded.dup
  expanded = +"\"#{expanded}\"" if /\s+/.match?(expanded)
  expanded << " #{args}" if args
  expanded
end
     | 
  
 
    
      
  
  
    #search_paths  ⇒ Object 
  
  
  
  
    
      
7
8
9 
     | 
    
      # File 'lib/facter/custom_facts/core/execution/windows.rb', line 7
def search_paths
  ENV['PATH'].split(File::PATH_SEPARATOR)
end 
     | 
  
 
    
      
  
  
    #which(bin)  ⇒ Object 
  
  
  
  
    
      
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 
     | 
    
      # File 'lib/facter/custom_facts/core/execution/windows.rb', line 13
def which(bin)
      return bin if /^echo$/i.match?(bin)
  if absolute_path?(bin)
    return bin if File.executable?(bin)
  else
    search_paths.each do |dir|
      dest = File.join(dir, bin)
      dest.gsub!(File::SEPARATOR, File::ALT_SEPARATOR)
      if File.extname(dest).empty?
        exts = ENV['PATHEXT']
        exts = exts ? exts.split(File::PATH_SEPARATOR) : DEFAULT_COMMAND_EXTENSIONS
        exts.each do |ext|
          destext = dest + ext
          return destext if File.executable?(destext)
        end
      end
      return dest if File.executable?(dest)
    end
  end
  nil
end
     |