oscargrower11 0 Newbie Poster

I've got an application that I call several times in a for loop using subprocess.call. Every time I call it, it starts minimized. I want it to be in a restored window. So what I've tried to do is get a handle on the window using win32gui.FindWindow. But in my current setup, FindWindow doesn't run until after the process is finished.

from subprocess import call
from os import getcwd
from win32gui import FindWindow
from win32gui import ShowWindow

settings_files = list([file_1, file_2, file_3])
#this creates a command "%executable_path%\spider_3.0.exe /run"
spider_app = "\"%s\" /run % ("join(getcwd(), "spider_3.0.exe"))

while len(settings_files) != 0:
    current_settings_file = settings_files.pop()
    import_settings(current_settings_file)
    call(spider_app)
    spider_window = FindWindow(None, "Spider 3.0.0")
    ShowWindow(spider_window, 9)

This obviously waits until the application has finished running before trying to get the window handle so it doesn't work. Detaching the process doesn't work either, as I need to wait for the process to finish, otherwise, I'll end up launching several instances of the application at once when I only want one to run at a time, the script will continue, and it will fail when it gets farther down and tries to use the output from the application.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.