Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions src/azure-cli-core/azure/cli/core/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
(get_file_json, truncate_text, shell_safe_json_parse, b64_to_hex, hash_string, random_string,
open_page_in_browser, can_launch_browser, handle_exception, ConfiguredDefaultSetter, send_raw_request,
should_disable_connection_verify, parse_proxy_resource_id, get_az_user_agent, get_az_rest_user_agent,
_get_parent_proc_name)
_get_parent_proc_name, is_wsl)
from azure.cli.core.mock import DummyCli


Expand Down Expand Up @@ -151,11 +151,13 @@ def test_proxy_resource_parse(self):

@mock.patch('webbrowser.open', autospec=True)
@mock.patch('subprocess.Popen', autospec=True)
def test_open_page_in_browser(self, sunprocess_open_mock, webbrowser_open_mock):
def test_open_page_in_browser(self, subprocess_open_mock, webbrowser_open_mock):
platform = sys.platform.lower()
open_page_in_browser('http://foo')
if platform == 'darwin':
sunprocess_open_mock.assert_called_once_with(['open', 'http://foo'])
if is_wsl():
subprocess_open_mock.assert_called_once_with(['powershell.exe', '-Command', 'Start-Process "http://foo"'])
elif platform == 'darwin':
subprocess_open_mock.assert_called_once_with(['open', 'http://foo'])
else:
webbrowser_open_mock.assert_called_once_with('http://foo', 2)

Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def open_page_in_browser(url):
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)])
return subprocess.Popen(['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.

Start-Process is async, so no need to use call to wait for the result.

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