S
S
SerKonRu2018-09-20 06:07:37
Python
SerKonRu, 2018-09-20 06:07:37

Launching an EXE file from Python and closing it after a while?

Good afternoon. It is necessary to launch an EXE file using Python, wait until this file performs all the actions (on average, the process takes about an hour) and close this process after a specified time.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
slepowl, 2018-09-20
@slepowl

subprocess google

D
Dmitry, 2018-09-20
@Trif

as I already wrote in the commentary, it depends on what method you have for determining the success of the completion of the EXE-shki. Here is the general pattern:

from os import startfile
from psutil import process_iter
from time import sleep

def is_completed(some_attribute):
    #if <your cheking method>: return True
    #else: return False

startfile(some_file)

while not is_completed(some_attribute):
    sleep(some_time)

for proc in process_iter():
    if proc.name() == some_file.split("\\")[-1]:
        proc.kill()

some_file - Your EXE file
some_time - time interval for completion checks (at your discretion)
some_attribute - if checks for the presence of an execution report, then the name of the report for os.path.exists(some_attribute) or reading the report with the search for the coveted line "well done"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question