I want to open Windows Explorer and select a specific file.
This is the API: explorer /select,"PATH"
. Therefore resulting in 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 non-shell mode (with pythonw
), a black shell window appears for a moment before the explorer is launched.
This is to be expected with os.system
. I've created the following function to launch processes without spawning a window:
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 fine for shell executables with no GUI. However it won't launch explorer.exe
.
How can I launch the process without spawning a black window before?