If I have a script in
C:\Users\Me\Desktop\M\MouseMover.py and another script in
C:\Users\Me\Desktop\M\AudioPlayer.py I want to have a THIRD script that can check if the mousemover and audioplayer are running, if not it needs to run them ( I'll just use subprocess for that part )
In this post( Check if a process is running or not on Windows? ) I found this snippet of code that works:
import subprocess
def process_exists(process_name):
call = 'TASKLIST', '/FI', 'imagename eq %s' % process_name
# use buildin check_output right away
output = subprocess.check_output(call).decode()
# check in last line for process name
last_line = output.strip().split('\r\n')[-1]
# because Fail message could be translated
return last_line.lower().startswith(process_name.lower())
but, it doesn't input a file path, rather a process name. This is a problem for me because I also have multiple scripts with the same name, and I need to check each individual one.
I tried this code with ONE of the 5 scripts that have the same name running, and it didnt run the remaining four because ONE myScript.py was running.