1

I wrote a simple GUI with a button to start a batch script as following:

from tkinter import *
import subprocess


class Application(Frame):
    def __init__(self, master):
        super().__init__(master)
        self.master = master

        self.btn = Button(self.master, text='Start program', command=self.btn_callback)
        self.btn.pack()

    @staticmethod
    def btn_callback():
        subprocess.run(r'start C:\temp\prog.bat', stdout=subprocess.PIPE, stderr=subprocess.PIPE)


root = Tk()
root.title('my app')
root.geometry("500x500")
app = Application(root)
root.mainloop()

The batch script again starts other processes like that:

@echo off
start "process1"
timeout /T 5
start "process2"
timeout /T 5
start "process3"
...

What i want is to disable the button in GUI until the user closes all processes which were started from the batch. Is it possible?

I have thought of starting all processes directly in the python script, and tracing the PID of these processes, but i'm not sure how could it be done getting the PID (considering the processes as variables, not as fixed names to search in tasklist) as well as how should they be traced in my GUI application? Thanks!

scmg
  • 1,904
  • 1
  • 15
  • 24
  • 2
    Read about [Is there a way to check if a subprocess is still running?](https://stackoverflow.com/a/43276598/7414759) – stovfl Mar 20 '19 at 15:24
  • this way i have to start all the processes directly in the python script. Is there any way to catch / poll them when i just start the batch in python script? Thanks anyway :-) – scmg Mar 21 '19 at 14:31
  • *"any way to catch / poll ... start the batch?"*: Not *catch/poll* but using [psutil](https://psutil.readthedocs.io/en/latest/) you should be able to **"see"** the processes running. – stovfl Mar 21 '19 at 15:05

0 Answers0