Reputation: 181
I want to automatically check if some KB is installed on the machine. Part of my python script:
import subprocess
result = subprocess.run(['cmd', '/c wmic qfe'], shell=True, stdout=subprocess.PIPE)
ftemp = open('mylog.txt','w') #just to check what is going wrong
ftemp.write(str(result.stdout))
ftemp.close()
if str(result.stdout).find('KB2999226')==-1:
print('Nah, you don't have KB')
sys.exit()
What I got in the shell while executing:
qfe" - Alias not found.
Nah, you don't have KB
mylog.txt:
b''
So, looks like some stupid problem with dashes or encodings. I've tried variety of commands, but nothing succeded. (Yeah, "dism" causes another tons of errors). Some advices?
Upvotes: 2
Views: 908
Reputation: 82805
Try separating all of the components into element in a list.
Replace:
result = subprocess.run(['cmd', '/c wmic qfe'], shell=True, stdout=subprocess.PIPE)
with
result = subprocess.run(['cmd', '/c', 'wmic', 'qfe'], shell=True, stdout=subprocess.PIPE)
Upvotes: 2
Reputation: 6748
Here is part of your problem:
print('Nah, you don't have KB')
should be
print("Nah, you don't have KB")
Upvotes: 2