Skip to content

Commit

Permalink
Merge 6edd3f9 into f6413ef
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasundhara Jagdale committed Jul 1, 2019
2 parents f6413ef + 6edd3f9 commit e4ad2a8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/train/platforms/detect/helpers/os_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ module Train::Platforms::Detect::Helpers
module Windows
def detect_windows
# try to detect windows, use cmd.exe to also support Microsoft OpenSSH
# setting pty to false to execute platform dection code as setting pty to true results in getting unwanted charters in response.
# resetting the same once output is gathered.

set_pty_false if @backend.class.to_s == "Train::Transports::SSH::Connection"
res = @backend.run_command("cmd.exe /c ver")
reset_pty if @backend.class.to_s == "Train::Transports::SSH::Connection"
return false if (res.exit_status != 0) || res.stdout.empty?

# if the ver contains `Windows`, we know its a Windows system
Expand All @@ -29,7 +34,9 @@ def detect_windows
# @see https://msdn.microsoft.com/en-us/library/bb742610.aspx#EEAA
# Thanks to Matt Wrock (https://github.com/mwrock) for this hint
def read_wmic
set_pty_false if @backend.class.to_s == "Train::Transports::SSH::Connection"
res = @backend.run_command("wmic os get * /format:list")
reset_pty if @backend.class.to_s == "Train::Transports::SSH::Connection"
if res.exit_status == 0
sys_info = {}
res.stdout.lines.each do |line|
Expand Down Expand Up @@ -115,5 +122,22 @@ def windows_uuid_from_registry
return unless result.exit_status == 0
result.stdout.chomp
end

private

# Setting pty flag to false
def set_pty_false
transport_options = @backend.instance_variable_get(:@transport_options)
@prev_pty = transport_options[:pty]
transport_options[:pty] = false
@backend.instance_variable_set(:@transport_options, transport_options)
end

# resetting to the pty flag to original value set by user
def reset_pty
transport_options = @backend.instance_variable_get(:@transport_options)
transport_options[:pty] = @prev_pty
@backend.instance_variable_set(:@transport_options, transport_options)
end
end
end

0 comments on commit e4ad2a8

Please sign in to comment.