Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hiding console when run in os.startfile()?

Tags:

python

windows

I have a .bat file with parameters; I run it using os.startfile(test.bat). Is there a way to hide its console? I tried using subprocess, it works well but when I close the parent program the subprocess that was compiled using py2exe console mode closes too.

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

Thanks

like image 933
unice Avatar asked Jan 27 '26 12:01

unice


1 Answers

Use shell=True and creationflags=subprocess.SW_HIDE with subprocess.Popen. This worked for me

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

In some releases of Python, SW_HIDE is not available in subprocess module. In that case, you may have to use _subprocess.SW_HIDE

like image 55
Imran Avatar answered Jan 30 '26 01:01

Imran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!