Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

jiasli
Copy link
Contributor

@jiasli jiasli commented Mar 29, 2021

Fix #332

The code is migrated from Azure CLI:

https://github.com/Azure/azure-cli/blob/3bff786b9e337aa35bb4cc64a09e5600a35663f8/src/azure-cli-core/azure/cli/core/util.py#L642-L648

    if is_wsl():   # windows 10 linux subsystem
        try:
            # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe
            # Ampersand (&) should be quoted
            return subprocess.call(['powershell.exe', '-Command', 'Start-Process "{}"'.format(url)])
        except OSError:  # WSL might be too old  # FileNotFoundError introduced in Python 3
            pass

_browse now tries webbrowser.open first. If that fails and WSL is detected, launch browser with powershell.exe.

As for why powershell.exe is preferred over cmd.exe, it is discussed in Azure/azure-cli#12851.

@jiasli
Copy link
Contributor Author

jiasli commented Mar 29, 2021

www-browser internally also uses powershell.exe

https://github.com/wslutilities/wslu/blob/221e85457c01e92db675cc7b24a49dfcdfacc6a9/src/wslu-header#L156

	"$(interop_prefix)$(sysdrive_prefix)"/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NonInteractiveExecutionPolicy Bypass -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::GetEncoding($cp); $@"

But we can keep it simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support auth code flow in WSL Ubuntu 18.04
2 participants