Nov-21-2017, 04:28 AM
Hi Gurus,
I am trying to print all services running on my windows laptop as a "three column output"
and i have written the following code.
However, i am only getting only one line output.
Could someone help/point me to the right direction?
I am trying to print all services running on my windows laptop as a "three column output"
and i have written the following code.
However, i am only getting only one line output.
Could someone help/point me to the right direction?
import re from subprocess import check_output with open('c:/users/dell/file.txt', 'w') as f: output=check_output("c:/windows/system32/sc query state= all").decode() print(output, file=f) print('Service Name \t DISPLAY NAME \t\t\t STATE') file=open('c:/users/dell/file.txt').readlines() for i in file: one=re.match(r'(SERVICE_NAME:)\s(.*)',i) if one is not None: x=one.group(2) for i in file: two=re.match(r'(DISPLAY_NAME:)\s(.*)',i) if two is not None: y=two.group(2) for i in file: three=re.search(r'(STATE.*:)\s(.*)',i) if three is not None: z=three.group(2) print(('%s \t %s \t %s')%(x,y,z))
Output:>>>
Service Name DISPLAY NAME STATE
WwanSvc WWAN AutoConfig 4 RUNNING
>>>