Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running shell commands without a shell window

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?

like image 253
aF. Avatar asked May 29 '10 16:05

aF.


People also ask

How do I run a shell script in Windows without Bash?

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.


1 Answers

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).

like image 126
Alex Martelli Avatar answered Sep 20 '22 06:09

Alex Martelli