Method: Train::Platforms::Detect::Helpers::Windows#detect_windows

Defined in:
lib/train/platforms/detect/helpers/os_windows.rb

#detect_windowsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/train/platforms/detect/helpers/os_windows.rb', line 5

def detect_windows
  res = @backend.run_command('cmd /c ver')
  return false if res.exit_status != 0 or res.stdout.empty?

  # if the ver contains `Windows`, we know its a Windows system
  version = res.stdout.strip
  return false unless version.downcase =~ /windows/
  @platform[:family] = 'windows'

  # try to extract release from eg. `Microsoft Windows [Version 6.3.9600]`
  release = /\[(?<name>.*)\]/.match(version)
  unless release[:name].nil?
    # release is 6.3.9600 now
    @platform[:release] = release[:name].downcase.gsub('version', '').strip
    # fallback, if we are not able to extract the name from wmic later
    @platform[:name] = "Windows #{@platform[:release]}"
  end

  # try to use wmic, but lets keep it optional
  read_wmic

  true
end