无法连接网络驱动器

时间:2017-08-22 19:28:48

标签: python python-3.x concatenation

我正在使用的脚本涉及连接用户输入以映射网络驱动器。我尝试过导入子进程和操作系统,但我没有取得任何成功。

下面我列出了使用子进程模块的代码示例。

import re
import subprocess

# Disconnect anything on M
subprocess.call(r'net use z: /del', shell=True)
#subprocess.call(r'net use z:', shell=True)

sending = input("Enter sending: ")
sending = sending.lower()

distribution = 'c0d'
service = 'c0s'

if re.match(sending[:3], distribution, flags=0):
   subprocess.call(r'net use z: \\+sending+-DB-00\fake_name\rce\help', shell=True)
   print("working distribution center")

elif re.match(sending[:3], service, flags=0):
    print("working service center")
else:
    print("try again")

抱歉,我忘记了我收到的错误 错误: 系统错误53已发生。

找不到网络路径。

我已经验证了我尝试映射的路径

1 个答案:

答案 0 :(得分:0)

不确定我是否正确理解您的需求,但是如果您想将sending变量中的用户输入连接到shell命令,则应将其移到引号之外:

import re
import subprocess

# Disconnect anything on M
subprocess.call(r'net use z: /del', shell=True)
#subprocess.call(r'net use z:', shell=True)

sending = input("Enter sending: ")
sending = sending.lower()

distribution = 'c0d'
service = 'c0s'

if re.match(sending[:3], distribution, flags=0):
   subprocess.call(r'net use z: \\'+sending+r'-DB-00\fake_name\rce\help', shell=True)
   print("working distribution center")

elif re.match(sending[:3], service, flags=0):
    print("working service center")
else:
    print("try again")
相关问题