Python 在不生成黑色shell窗口的情况下启动GUI进程

Python 在不生成黑色shell窗口的情况下启动GUI进程,python,subprocess,explorer,Python,Subprocess,Explorer,我想打开Windows资源管理器并选择一个特定的文件。 这是API:explorer/select,“PATH”。因此产生以下代码(使用python 2.7): 代码工作正常,但是当我切换到非shell模式(使用pythonw)时,在资源管理器启动之前会出现一个黑色的shell窗口 这在os.system中是意料之中的。我创建了以下函数来启动进程,而无需生成窗口: import subprocess, _subprocess def launch_without_console(cmd):

我想打开Windows资源管理器并选择一个特定的文件。 这是API:
explorer/select,“PATH”
。因此产生以下代码(使用python 2.7):

代码工作正常,但是当我切换到非shell模式(使用
pythonw
)时,在资源管理器启动之前会出现一个黑色的shell窗口

这在
os.system
中是意料之中的。我创建了以下函数来启动进程,而无需生成窗口:

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
这适用于没有GUI的shell可执行文件。但是,它不会启动
explorer.exe


我如何才能在不产生黑色窗口的情况下启动流程?

这似乎是不可能的。但是,可以从
win32api
访问它。我使用了找到的代码:


令人惊讶的是:我在C/C++代码上尝试了WinExec和ShellExec,它给了我同样的行为。你能看看这个问题吗?谢谢
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
from win32com.shell import shell

def launch_file_explorer(path, files):
    '''
    Given a absolute base path and names of its children (no path), open
    up one File Explorer window with all the child files selected
    '''
    folder_pidl = shell.SHILCreateFromPath(path,0)[0]
    desktop = shell.SHGetDesktopFolder()
    shell_folder = desktop.BindToObject(folder_pidl, None,shell.IID_IShellFolder)
    name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, 0), item) for item in shell_folder])
    to_show = []
    for file in files:
        if name_to_item_mapping.has_key(file):
            to_show.append(name_to_item_mapping[file])
        # else:
            # raise Exception('File: "%s" not found in "%s"' % (file, path))

    shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0)
launch_file_explorer(r'G:\testing', ['189.mp3'])