diff --git a/lib/webdrivers/chrome_finder.rb b/lib/webdrivers/chrome_finder.rb index 20f28e94..437ee066 100644 --- a/lib/webdrivers/chrome_finder.rb +++ b/lib/webdrivers/chrome_finder.rb @@ -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