Unverified Commit d562b00c authored by Earle F. Philhower, III's avatar Earle F. Philhower, III Committed by GitHub

Use Powershell to find UF2 drive if WMIC fails (#476)

Microsoft is deprecating WMIC, so fall back to a Powershell call in
case of failure to ruin WMIC.

Belt and suspenders, set PowerShell non-interactive mode and null STDIN.
parent ba92377e
......@@ -228,9 +228,21 @@ def to_str(b):
def get_drives():
drives = []
if sys.platform == "win32":
r = subprocess.check_output(["wmic", "PATH", "Win32_LogicalDisk",
"get", "DeviceID,", "VolumeName,",
"FileSystem,", "DriveType"])
try:
r = subprocess.check_output(["wmic", "PATH", "Win32_LogicalDisk",
"get", "DeviceID,", "VolumeName,",
"FileSystem,", "DriveType"])
except:
try:
nul = open("nul:", "r")
r = subprocess.check_output(["powershell", "-NonInteractive", "-Command",
"Get-WmiObject -class Win32_LogicalDisk | "
"Format-Table -Property DeviceID, DriveType, Filesystem, VolumeName"],
stdin = nul)
nul.close()
except:
print("Unable to build drive list");
sys.exit(1)
for line in to_str(r).split('\n'):
words = re.split('\s+', line)
if len(words) >= 3 and words[1] == "2" and words[2] == "FAT":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment