Let's first talk about what I'm trying to do (using Python 3.x): As a part of a small VFX pipeline, I'm working on a tool which is supposed to launch programs (e.g. Blender) after setting a couple of environment variables. No issues with this part directly. The issue is the visibility of the console. There are three requirements that I find conflicting with each other.
Requirement 1: The console of the tool itself will need to be hidden.
Requirement 2: A separate cmd/console needs to be launched for Blender, as the output of this tool needs to be accessible. (For if I work on a script in Blender I need to be able to see errors and prints.)
Requirement 3: The tool itself should be hidden once the Blender launches, and should come back if Blender is closed. (This is so that it can quickly be restarted in case of a crash. A lot of VFX software is incredibly unstable once you are working on heavier scenes.)
Individually I'm able to cover each of the requirements. I'm even able to cover 2 different ones at the same time, but I struggle meeting all 3 of them at once. (I'm using Tkinter for the UI)
Option number 1:
command = "C:\Program Files\Blender Foundation\Blender 2.91\blender.exe"
ui.withdraw()
os.system(command)
ui.update()
ui.deiconify()
Using os.system will freeze the tool while Blender is running. It will unfreeze and thus also unhide as soon as Blender crashes. But I'm missing the console output. (The tool itself is launched using subprocess.Popen. This is on purpose as I won't need the console of the tool itself, I only want the console to show up once Blender is actually launched.)
Alternatively, I tried:
ui.withdraw()
os.system(f'start cmd /C {command}') # also tried the same command using subprocess.Popen
ui.update()
ui.deiconify()
Launching a console and executing Blender from within it gives me the desired console, but the tool doesn't wait anymore until Blender is closed. It's immediately back to being visible as it considers launching the cmd as the end of the command.
I could use the second method to start the tool itself and then use the first method within it. That solves both Requirement 3 & 4, but it also means the console will be visible before Blender is launched failing requirement #2.
PS: Apologies, if anything is chaotic or overcomplicated. I'm a VFX artist and not a programmer and I only use python now and then. I feel like my knowledge is very imbalanced. It's quite advanced in regards to some topics but has big gaps regarding others.