Nov-23-2017, 09:01 AM
#!python3 import re from subprocess import check_output with open('file.txt', 'w') as f: output=check_output("c:/windows/system32/sc query state= all").decode("utf-8", "ignore") print(output, file=f) lines = open('file.txt').readlines() x = [ ] for line in lines: one=re.match(r'(SERVICE_NAME:)\s(.*)', line) if one: x.append(one.group(2)) y = [ ] for line in lines: two=re.match(r'(DISPLAY_NAME:)\s(.*)', line) if two: y.append(two.group(2)) z = [ ] for line in lines: three=re.search(r'(STATE.*:)\s(.*)', line) if three: z.append(three.group(2)) print('%-20s %-60s %-10s' % ("Service Name", "DISPLAY NAME", "STATE")) for a,b,c in zip(x, y, z): print('%-20s %-60s %-10s' % (a, b, c)) #done