How to run an executable file in Python without a popup console executable?

So, I have a python script that launches the Tkinter GUI, which has a button widget that calls an executable file that is written in C. But every time I click this button, a console appears in which this C executable is launched and then close after the run is done. I call the executable using

import subprocess    
subprocess.call[args]

How to hide this popup? Because I use the GUI, and it is not very nice if the console does not appear anywhere.

+4
source share
1 answer

Use the startupinfo subprocess.Popen() class parameter .

startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
subprocess.Popen(command, startupinfo=startupinfo)

, popen:

subprocess.Popen(['program.exe','arg1','arg2'], startupinfo=startupinfo)

Edit:
, , , DETACHED_PROCESS subprocess.call.

this MSDN:

DETACHED_PROCESS 0x00000008 - ( ). AllocConsole , . , . " ". CREATE_NEW_CONSOLE.

DETACHED_PROCESS = 0x00000008
subprocess.call('program.exe', creationflags=DETACHED_PROCESS)
+3

Source: https://habr.com/ru/post/1683654/


All Articles