With either subprocess.call
or subprocess.Popen
, executing a shell command makes a shell window quicky appear and disappear.
How can I run the shell command without the shell window?
1] Execute Shell Script file using WSLGo to Settings > Update & Security > For Developers. Check the Developer Mode radio button. And search for “Windows Features”, choose “Turn Windows features on or off”. Scroll to find WSL, check the box, and then install it.
I imagine your observation is limited to Windows, since that, I believe, is the only platform on which you'll get that "console flash" issue. If so, then the docs offer the following semi-helpful paragraph:
The startupinfo and creationflags, if given, will be passed to the underlying CreateProcess() function. They can specify things such as appearance of the main window and priority for the new process. (Windows only)
Unfortunately the Python online docs do not reproduce the relevant portion of the Windows API docs, so you have to locate those elsewhere, e.g. starting here on MSDN which leads you here for the creationflags
, and specifically to
CREATE_NO_WINDOW
0x08000000
The process is a console application that is being run without a console window. Therefore, the console handle for the application is not set.
So, adding creationflags=0x08000000
to your Popen
call should help (unfortunately I have no Windows-running machine on which to try this out, so you'll have to try it yourself).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With