I want to open Windows Explorer and select a specific file. This is the API: explorer /select,"PATH" . Therefore, the result is the following code (using python 2.7):
import os PATH = r"G:\testing\189.mp3" cmd = r'explorer /select,"%s"' % PATH os.system(cmd)
The code works fine, but when I switch to pythonw mode (with pythonw ), a black shell window appears a moment before the pythonw starts.
This can be expected with os.system . I created the following function to start processes without a window appearing:
import subprocess, _subprocess def launch_without_console(cmd): "Function launches a process without spawning a window. Returns subprocess.Popen object." suinfo = subprocess.STARTUPINFO() suinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW p = subprocess.Popen(cmd, -1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=suinfo) return p
This works great for shell executables without a GUI. However, it does not start explorer.exe .
How to start a process without a black window before?
iTayb source share