Cross-platform subprocess with hidden window
You can reduce one line :)
startupinfo = Noneif os.name == 'nt': startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOWproc = subprocess.Popen(command, startupinfo=startupinfo)
Just a note: for Python 2.7 I have to use subprocess._subprocess.STARTF_USESHOWWINDOW
instead of subprocess.STARTF_USESHOWWINDOW
.
I'm not sure you can get much simpler than what you've done. You're talking about optimising out maybe 5 lines of code. For the money I would just get on with my project and accept this as a consquence of cross-platform development. If you do it a lot then create a specialised class or function to encapsulate the logic and import it.