I've working on a python program and I need it to run once I open an app. Is it possible ? If so how would I implement it ?
-Any help is appreciated.
P.S. The program I'm writing is supposed to run on windows.
CodePudding user response:
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 isProcessRunning(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(!isProcessRunning('NameOfTheProcess') # only continue as long as the return is False
time.sleep(10) # wait 10 seconds
Anyway you could use psutil. For further information: https://psutil.readthedocs.io/en/latest/