mirror of https://github.com/ARMmbed/mbed-os.git
usb_device-msd test: fix powershell unmount script issue
Running PowerShell script on some windows machines is blocked. To avoid this problem script was replace by the code run directly in PowerShell console.pull/10767/head
parent
4bd1d15d01
commit
18285168fd
|
|
@ -204,25 +204,16 @@ class MSDUtils(object):
|
|||
@staticmethod
|
||||
def _unmount_windows(serial):
|
||||
disk_path = MSDUtils._disk_path_windows(serial)
|
||||
tmp_file = tempfile.NamedTemporaryFile(suffix='.ps1', delete=False)
|
||||
try:
|
||||
# create unmount script
|
||||
tmp_file.write('$disk_leter=$args[0]\n')
|
||||
tmp_file.write('$driveEject = New-Object -comObject Shell.Application\n')
|
||||
tmp_file.write('$driveEject.Namespace(17).ParseName($disk_leter).InvokeVerb("Eject")\n')
|
||||
# close to allow open by other process
|
||||
tmp_file.close()
|
||||
cmd_string = r'(New-Object -comObject Shell.Application).Namespace(17).ParseName("{}").InvokeVerb("Eject")'.format(disk_path)
|
||||
|
||||
try_count = 10
|
||||
while try_count:
|
||||
p = subprocess.Popen(["powershell.exe", tmp_file.name + " " + disk_path], stdout=sys.stdout)
|
||||
p.communicate()
|
||||
try_count -= 1
|
||||
if MSDUtils._disk_path_windows(serial) is None:
|
||||
return True
|
||||
time.sleep(1)
|
||||
finally:
|
||||
os.remove(tmp_file.name)
|
||||
try_count = 10
|
||||
while try_count:
|
||||
p = subprocess.Popen(["powershell.exe", cmd_string], stdout=sys.stdout)
|
||||
p.communicate()
|
||||
try_count -= 1
|
||||
if MSDUtils._disk_path_windows(serial) is None:
|
||||
return True
|
||||
time.sleep(1)
|
||||
|
||||
return False
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue