2016-03-31 229 views
0

我使用下面的代碼到網絡驅動器,以我的機器映射:映射網絡驅動器

cmd = r"net use I: %s /P:YES" % network_path_toMyDrive 
os.system("@ping 127.0.0.1 -n 2 -w 1000 > nul") # I found that this line is important to refresh windows to show the new drive 
os.system("@ping 127.0.0.1 -n 5 -w 1000 > nul") 
cmd = r"net use I: %s /P:YES" % selectIdriveChoices[I] 
# call(cmd, shell=True) 
p = Popen(cmd, stdin=PIPE, shell=True) 
p.stdin.write("y\n") 
os.system("@ping 127.0.0.1 -n 2 -w 1000 > nul") 
os.system("@ping 127.0.0.1 -n 5 -w 1000 > nul") 

但是,我不能提供時,我改變了驅動器,同時它是開放的迴應:

There are open files and/or incomplete directory searches pending on the connection to I:. 

Is it OK to continue disconnecting and force them closed? (Y/N) [N]: 
System error 85 has occurred. 

The local device name is already in use. 

我只是想提供「y」,如果我看到此消息。

+0

https://pexpect.readthedocs.org/en/stable/ –

+0

感謝你的回覆@Rogalski。我只是不想讓它複雜化。我需要的只是提供一個在驅動器打開時刪除驅動器的答案。 – Omar

回答

0

我不得不強制刪除映射驅動器,如果它是在使用中通過添加/ YES鍵命令:

cmd = 'net use I: /D /YES' 
相關問題