I have a program with a GUI that runs an external program through a Popen call:
p = subprocess.Popen("<commands>" , stdout=subprocess.PIPE , stderr=subprocess.PIPE , cwd=os.getcwd())
p.communicate()
But a console pops up, regardless of what I do (I've also tried passing it NUL for the file handle). Is there any way to do that without getting the binary I call to free its console?
According to Python 2.7 documentation and Python 3.7 documentation, you can influence how
Popen
creates the process by settingcreationflags
. In particular, theCREATE_NO_WINDOW
flag would be useful to you.just do
subprocess.Popen([command], shell=True)
You might be able to just do
subprocess.Popen([command], shell=False)
.That's what I use anyways. Saves you all the nonsense of setting flags and whatnot. Once named as a .pyw or run with pythonw it shouldn't open a console.
From here:
This works nicely in the win32api. The other solutions were not working for me.