I am trying to read usernames by sending a cmd command
root = subprocess.check_output(
"netsh wlan show profiles", shell=True, stderr=subprocess.STDOUT).decode()
Suppose i get below Output from the root cmd
sample root output = ["All User Profile : L",
"All User Profile : Sp",
"All User Profile : Pixel",
"All User Profile : Home",
"All User Profile : lph",
"All User Profile : lp"
]
Here i need to get the characters after ":" like L,Sp etc for this i am trying the below code but i am getting "All User Profile" how can i get the required OP
for x in list:
if "User" in x:
print(x.split(":", 1)[0])
if i do print(x.split(":", 1)[1])
i am gtting list index out of range error
CodePudding user response:
Try with -1 in place of 0
for x in root.splitlines():
if "User" in x:
print(x.split(":",1)[-1])