Reputation: 1
I want to insert a variable in place of the ip address this is my working code without the variable:
subprocess.call(r'net use T: \\192.168.1.10\myshare /PERSISTENT:YES', shell=True)
this is my not workings attempts with the variable:
myip = "192.168.1.10"
subprocess.call(r'net use T: \\'+myip'\myshare /PERSISTENT:YES', shell=True)
#or:
subprocess.call(r'net use T: \\', 'myip', '\myshare /PERSISTENT:YES', shell=True)
#or:
subprocess.call(r'net use T: \\'+myip+'\myshare /PERSISTENT:YES', shell=True)
#or:
subprocess.call(r'net use T: \\+myip+\myshare /PERSISTENT:YES', shell=True)
none of these works any suggestions?
Upvotes: 0
Views: 62
Reputation: 54698
You need the raw prefix on any substring that has backslashes:
subprocess.call(r'net use T: \\'+myip+r'\myshare /PERSISTENT:YES', shell=True)
Or:
subprocess.call(
['net', 'use', rf'\\{myip}\myshare', '/PERSISTENT:YES'],
shell=True
)
Upvotes: 1