您应该使用win32api并隐藏窗口,例如,使用win32gui.EnumWindows可以枚举所有顶部窗口并隐藏窗口
这是一个小示例,您可以执行以下操作:
import subprocessimport win32guiimport timeproc = subprocess.Popen(["notepad.exe"])# lets wait a bit to app to starttime.sleep(3)def enumWindowFunc(hwnd, windowList): """ win32gui.EnumWindows() callback """ text = win32gui.GetWindowText(hwnd) className = win32gui.GetClassName(hwnd) #print hwnd, text, className if text.find("Notepad") >= 0: windowList.append((hwnd, text, className))myWindows = []# enumerate thru all top windows and get windows which are ourswin32gui.EnumWindows(enumWindowFunc, myWindows)# now hide my windows, we can actually check process info from GetWindowThreadProcessId# http://msdn.microsoft.com/en-us/library/ms633522(VS.85).aspxfor hwnd, text, className in myWindows: win32gui.ShowWindow(hwnd, False)# as our notepad is now hidden# you will have to kill notepad in taskmanager to get past next lineproc.wait()print "finished."


