windows - Net Use in Python 3 -


anyone me python trying use net use, don't know diferences between / in python , perl, because code in perl works

$runmap = "c:\\windows\\system32\\net.exe use \\\\$ip\\d\$ /persistent:no /user:$user_name $passwd";  system($runmap); 

but in python 3 don't work

os.system("c:/windows/system32/net.exe use z: \\\\ip/d:/ /persistent:no /user:user pass") 

perl using interpolation, is, possible embed variables inside double quoted string, since perl 5 interpolated variables start $ or @ marker. in case embedding $user_name , $passwd.

python variable names not prefixed "magic character" (sigil), cannot embed them inside strings except using formatting statements. there couple of regimes, here 1 similar idea printf:

cmd = "c:/windows/system32/net.exe use z: \\\\ip/d:/ /persistent:no /user:%s %s" % (user, passwd)  os.system(cmd) 

as ex-perlmonger missed interpolation wrote python module support it. while learnt lot python doing it, otherwise waste of time. python programming different style, don't need interpolation more.

by way, unlike perl's system(), python's os.system() always spawn shell (as c's). therefore considered deprecated. subprocess.popen() method gives more control.


Comments