I’m writing a wxPython app that uses of a library which runs external programs.
All is fine.
When I freeze my app (with cxfreeze), I see console windows opening and closing. I can reproduce the problem without freezing my app when running it with pythonw.
I search the Internet but didn’t find any solution.
How can I get rid of these console windows ?
There’s no such option with cxfreeze. However, I use base = "Win32GUI". This let remove the console window of the wx app.
To be clear, the problem is not with the console window associated to the wx app. The problem is with console windows created when external programs are run from the wx app.
When the console window associated with the wx app is not discarded, children processes send their output in this console and no other console window is created.
When the console window associated with the wx app is discarded (when freezed or run with pythonw), a new console window is created for each child process.
What I what to achieve is to discard all console windows.
Unfortunately, the external program launches are done by a third party library. I have no control on it.
One solution might be to create a console window with wxPython API, attach it to the wx app and hide it. This way, children processes would direct their outputs to this hidden console window. But is this possible ?
I don’t understand: are you or are you not starting this third-party app? Your code sample simply calls “os.system”…
If you are starting this third party app then I would start it in a separate thread that starts a process using subprocess as I mentioned before. Otherwise my apologies as I have probably not understood your problem correctly.
My example is a very simple example to be run as is, without dependencies.
In fact, I use a third party library (youtube-dl) which runs external processes.
The problem is that external programs are run from a library I have no control on. These external programs either use their parent console, or create a new one if the parent has no console.
Running a wx app in base mode creates a console that is used by children processes.
Running a wx app in gui mode discards the app console. As a consequence, children processes create their own console.
In both cases, console windows are created (and visible).
My work around is to run my wx app in base mode and hide the console window.
Here is how to do that :
This way, when the frozen wx app is launched, the console window is shown for some time (depending on app startup duration) and hidden by the app. Children processes attach to this hidden console so no new console is created when they are run.