Link to home
Start Free TrialLog in
Avatar of adbyits
adbyits

asked on

Detect if program is running using python3

Hi all ia am going well with my script to check for a program and if its not there then run another program, my issue is that even if its find that the program is there it will try to run it any way, on a leavel of 1 to 100 how good am at code maybe 40 so forgive me if it is a dumb mistake, here isthe code , i might be completely wrong so pelase tell me if i am

# Created By ADBY IT AND MEDIA SOLUTIONS
# Adam R Wolarczuk
# 19th March 2020
# Version 0.1
# Beta


# Class for Detect if program is running
import psutil
import subprocess
import pyautogui
import time

for p in psutil.process_iter(attrs=['pid', 'name']):
    if p.info['name'] == "Discord.exe":
        print("yes", (p.info['name']))

    else:
        print("I am here")
        subprocess.Popen(r"C:\FrazerClient\FrazerClient.exe")
        #print("no", (p.info['name']))


# If Program is running
# if the program is not running
# Log to file
# send email to imporm report
Avatar of Louis LIETAER
Louis LIETAER
Flag of France image

Hi,

After a quick read, the filepath is not correct, you should have written:
    subprocess.Popen('C:\\FrazerClient\\FrazerClient.exe')

Let me know if this helps.
Avatar of noci
noci

For python programs the .exe that is running is python.exe / python3.exe / python37.exe etc. depending on distro & version etc.
ASKER CERTIFIED SOLUTION
Avatar of adbyits
adbyits

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good job for https://www.experts-exchange.com/questions/29177073/Detect-if-program-is-running-using-python3.html#a43055932 , you originally posted :

for p in psutil.process_iter(attrs=['pid', 'name']):
    if p.info['name'] == "Discord.exe":
        print("yes", (p.info['name']))

    else:
        print("I am here")
        subprocess.Popen(r"C:\FrazerClient\FrazerClient.exe")
        #print("no", (p.info['name']))

Those was not the same exe, I was wondering if it was wanted apparently no.