8000 Use Powershell to find UF2 drive if WMIC fails (#476) · randomllama/arduino-pico@d562b00 · GitHub
[go: up one dir, main page]

Skip to content

Commit d562b00

Browse files
Use Powershell to find UF2 drive if WMIC fails (earlephilhower#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.
1 parent ba92377 commit d562b00

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tools/uf2conv.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,21 @@ def to_str(b):
228228
def get_drives():
229229
drives = []
230230
if sys.platform == "win32":
231-
r = subprocess.check_output(["wmic", "PATH", "Win32_LogicalDisk",
232-
"get", "DeviceID,", "VolumeName,",
233-
"FileSystem,", "DriveType"])
231+
try:
232+
r = subprocess.check_output(["wmic", "PATH", "Win32_LogicalDisk",
233+
"get", "DeviceID,", "VolumeName,",
234+
"FileSystem,", "DriveType"])
235+
except:
236+
try:
237+
nul = open("nul:", "r")
238+
r = subprocess.check_output(["powershell", "-NonInteractive", "-Command",
239+
"Get-WmiObject -class Win32_LogicalDisk | "
240+
"Format-Table -Property DeviceID, DriveType, Filesystem, VolumeName"],
241+
stdin = nul)
242+
nul.close()
243+
except:
244+
print("Unable to build drive list");
245+
sys.exit(1)
234246
for line in to_str(r).split('\n'):
235247
words = re.split('\s+', line)
236248
if len(words) >= 3 and words[1] == "2" and words[2] == "FAT":

0 commit comments

Comments
 (0)
0