class Facter::Core::Execution::Windows
Constants
- ABSOLUTE_PATH_REGEX
- DEFAULT_COMMAND_EXTENSIONS
- DOUBLE_QUOTED_COMMAND
Public Instance Methods
absolute_path?(path)
click to toggle source
# File lib/facter/custom_facts/core/execution/windows.rb, line 41 def absolute_path?(path) !!(path =~ ABSOLUTE_PATH_REGEX) end
execute(command, options = {})
click to toggle source
Calls superclass method
Facter::Core::Execution::Base#execute
# File lib/facter/custom_facts/core/execution/windows.rb, line 65 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)
click to toggle source
# File lib/facter/custom_facts/core/execution/windows.rb, line 47 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}\"" if /\s+/.match?(expanded) expanded << " #{args}" if args expanded end
search_paths()
click to toggle source
# File lib/facter/custom_facts/core/execution/windows.rb, line 5 def search_paths ENV['PATH'].split(File::PATH_SEPARATOR) end
which(bin)
click to toggle source
# File lib/facter/custom_facts/core/execution/windows.rb, line 11 def which(bin) # `echo` is allowed for facter 3.x compatibility, otherwise # all commands much be found on the PATH or absolute. 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