0

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.

flockland
  • 3
  • 1
  • 1
    You need to [check the command line arguments](https://superuser.com/questions/415360/how-do-i-find-out-command-line-arguments-of-a-running-program) to get the python script, seems like `wmi` or `psutil` can do that too. – ivvija Feb 01 '23 at 16:45

0 Answers0