Issue
I've working on a windows python program and I need it to run once I open an app. Is it possible ? If so how would I implement it ?
Solution
We need some information, what did you want to do? Did you wanna know, if a process is started and then you will continue you python script? Than you can do this:
import psutil
def is_process_running(processName):
for process in psutil.process_iter(): # iterates through all processes from your OS
try:
if processName.lower() in process.name().lower(): # lowers the name, because "programm" != proGramm"
return True # if the process is found, then return true
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): # some failures what could go wrong
pass
return False;
while(!is_process_running('nameOfTheProcess') # only continue as long as the return is False
time.sleep(10) # wait 10 seconds
For further information: psutil-docs
Answered By - robni
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.