Hide console at startup in os.startfile ()?

I have a file .batwith parameters; I run it with os.startfile(test.bat). Is there a way to hide my console? I tried to use subprocess, it works well, but when I close the parent program, it will close subprocess, compiled using py2execonsole mode.

info = subprocess.STARTUPINFO()
info.dwFlags=1
info.wShowWindow=0 
subprocess.Popen(test.bat,startupinfo=info)

thank

+3
source share
1 answer

Use shell=Trueand creationflags=subprocess.SW_HIDEwith subprocess.Popen. It worked for me

subprocess.Popen(['test.bat'], shell=True, creationflags=subprocess.SW_HIDE)

In some versions of Python, it is SW_HIDEnot available in the module subprocess. In this case, you may have to use_subprocess.SW_HIDE

+7
source

All Articles