Oct-07-2018, 09:58 AM
(Oct-07-2018, 09:45 AM)snippsat Wrote: You have to clean up what you get fromgreat its working but now how i cant now which of pro_find = ["opera.exe" , "chrome.exe" , "iexplore.exe" , "firefox.exe" , "microsoftedgecp.exe"]d = os.popen
.
d
will be a big sting with mixed in \n \r and empty stings.
You should use subprocess,and notos.popen()
which is deprecated.
Quote:Deprecated since version 2.6: All of the os.popen*() functions are obsolete. Use the subprocess module.
If doing it subprocess and can usecheck_output
to get output.
Ideally would like to removeshell=True
,but command did like to be spilt out to a list.
import subprocess pro = subprocess.check_output("""wmic process get name | findstr /v "Name 'System Idle Process' System""", shell=True) pro_string = pro.decode('utf-8') lst = [] for item in pro_string.split('\r'): lst.append(item.strip()) process_list = filter(None, lst) process_list = list(process_list) #print(process_list)Test output,see now that have clean up list with processes.
>>> process_list[:6] ['Registry', 'smss.exe', 'csrss.exe', 'wininit.exe', 'csrss.exe', 'winlogon.exe'] >>> pro_find = ['chrome.exe', 'smss.exe'] >>> any(p in process_list for p in pro_find) TrueAlternative use psutil is good for this kind of stuff.
exist and pass it name to
qassam = os.popen("dir /s /b {}".format("pass the process name founded from the list ")).read().strip()