Skip to content

Commit

Permalink
WSL - Suppress harmless error when Powershell 6 or higher is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
kapoorlakshya committed Jan 4, 2021
1 parent 73acf52 commit e5ff19b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/webdrivers/chrome_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ def linux_location
end

def win_version(location)
System.call("pwsh.exe -command \"(Get-ItemProperty '#{location}').VersionInfo.ProductVersion\"")&.strip
# When Powershell 6 or higher (pwsh.exe) is not found, an error `sh: 1: pwsh.exe: not found`
# is printed to the console (STDERR). This can be confusing to users on older versions (powershell.exe)
# because this error is rescued and older PS is used instead.
# 2>&1 at the end redirects STDERR to STDOUT, which IO.popen intercepts, and the error is no longer printed
# to the console.
System.call("pwsh.exe -command \"(Get-ItemProperty '#{location}').VersionInfo.ProductVersion\" 2>&1")&.strip
rescue StandardError
Webdrivers.logger.debug 'Powershell 6 or higher (pwsh.exe) not found. Trying powershell.exe instead...'
System.call("powershell.exe \"(Get-ItemProperty '#{location}').VersionInfo.ProductVersion\"")&.strip
end

Expand Down

0 comments on commit e5ff19b

Please sign in to comment.