Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/azure-cli-core/azure/cli/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ def open_page_in_browser(url):

if is_wsl(): # windows 10 linux subsystem
try:
return subprocess.call(['cmd.exe', '/c', "start {}".format(url.replace('&', '^&'))])
# 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)])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without double quote, powershell.exe gives error:

# WSL
$ powershell.exe -Command 'Start-Process https://github.com/?a=1&b=2'
At line:1 char:38
+ Start-Process https://github.com/?a=1&b=2
+                                      ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : AmpersandNotAllowed

This works:

$ powershell.exe -Command 'Start-Process "https://github.com/?a=1&b=2"'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, is it a powershell executable inside WSL?

except OSError: # WSL might be too old # FileNotFoundError introduced in Python 3
pass
elif platform_name == 'darwin':
Expand Down