How to get this processes category on python?
I try to get all process, but I don't now how to get only this category of processes.
#!/usr/bin/python
# -*- coding: utf8 -*-
import subprocess
import psutil
pids = []
cmd = 'powershell "gps | where {$_.MainWindowTitle } | select Id'
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
for line in proc.stdout:
if line.rstrip():
#print(line.decode().rstrip())
pids.append(line.decode().rstrip())
pids.remove(' Id')
pids.remove(' --')
for pid in pids:
process = psutil.Process(int(pid))
process_name = process.name()
print(process_name)
This is my answer