Skip to content

Conversation

@jiasli
Copy link
Member

@jiasli jiasli commented Apr 2, 2020

Description

Fix #11927: az login uses cmd.exe when using WSL which doesn't support UNC paths

az login in WSL shows warning:

user2@DESKTOP-37TQVO0:~$ az login
'\\wsl$\Ubuntu\home\user2'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

This can also be reproduced by running cmd.exe directly in WSL:

user2@DESKTOP-37TQVO0:~$ cmd.exe
'\\wsl$\Ubuntu\home\user2'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
Microsoft Windows [Version 10.0.18363.720]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Windows>

powershell.exe on the other hand doesn't have this problem and can handle UNC paths correctly:

user2@DESKTOP-37TQVO0:~$ powershell.exe
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\Ubuntu\home\user2>   

This PR removes the UNC path warning by calling powershell.exe instead of cmd.exe to open the browser.

Testing Guide

Use either method:

Install Azure CLI in WSL from source

# Go to the CLI source folder D:\cli
cd /mnt/d/cli

# Create a virtual environment
python3 -m venv envwsl

# Activate the virtual environment
. envwsl/bin/activate

pip install azdev
azdev setup -c

az login

Install Azure CLI in WSL with apt

Follow Install Azure CLI with apt. Then replace
C:\Users\{username}\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\opt\az\lib\python3.6\site-packages\azure\cli\core\util.py with the util.py file in this PR.

Then run az login. The warning is gone.

@yonzhan
Copy link
Collaborator

yonzhan commented Apr 2, 2020

add to S168

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?

@jiasli
Copy link
Member Author

jiasli commented Apr 3, 2020

@GarrettGeorge, do you mind also doing a quick test on whether this works for you?

@yonzhan yonzhan modified the milestones: S168, S169 - For Build Apr 18, 2020
Copy link
Member

@qianwens qianwens left a comment

Choose a reason for hiding this comment

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

:shipit:

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

az login uses cmd.exe when using WSL which doesn't support UNC paths

5 participants