operating system - Python Running OS command with quotes inside -
#!/usr/bin/python import os readline = open('desktops.txt','r') line in readline: machinename = line query = os.system('wmic -u corp.fakedomain.com/domainusername%password //192.168.1.100 "select * win32_useraccount localaccount = true"|grep "500|"|cut -d "\\" -f 2|cut -d "|" -f1')
i receiving following error...
myhostname:~# ./getlocaladminnames.py sh: syntax error: unterminated quoted string sh: syntax error: unterminated quoted string sh: syntax error: unterminated quoted string sh: syntax error: unterminated quoted string sh: syntax error: unterminated quoted string
then after resolve error substitute ip machinename variable.
any appreciated.
you should escape backslashes. replace \\
\\\\
:
os.system('wmic -u corp.fakedomain.com/domainusername%password //192.168.1.100 "select * win32_useraccount localaccount = true"|grep "500|"|cut -d "\\\\" -f 2|cut -d "|" -f1')
or, make string raw
adding r
prefix:
os.system(r'wmic -u corp.fakedomain.com/domainusername%password //192.168.1.100 "select * win32_useraccount localaccount = true"|grep "500|"|cut -d "\\" -f 2|cut -d "|" -f1')
also see:
Comments
Post a Comment