Use startupinfo
parameter of subprocess.Popen()
class.
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
subprocess.Popen(command, startupinfo=startupinfo)
If you wish to pass arguments to the process you should pass it as an array to popen
:
subprocess.Popen(['program.exe','arg1','arg2'], startupinfo=startupinfo)
Edit:
As Felix pointed out in the comments, in case that you want the child to don't have console at all you should use the DETACHED_PROCESS
flag and subprocess.call
.
As described in this MSDN page:
DETACHED_PROCESS 0x00000008 - For console processes, the new process does not inherit its parent's
console (the default). The new process can call the AllocConsole
function at a later time to create a console. For more information,
see Creation of a Console. This value cannot be used with
CREATE_NEW_CONSOLE.
DETACHED_PROCESS = 0x00000008
subprocess.call('program.exe', creationflags=DETACHED_PROCESS)