本文介绍了使子进程在Windows上隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 作为我努力编写一个能够处理GUI的测试工具的一部分 很好,我正在努力建立我的方式可以在 Windows上启动GUI进程,而不会启动窗口。所以我试着隐藏窗口 如下: info = subprocess.STARTUPINFO() info.dwFlags | = subprocess.STARTF_USESHOWWINDOW info.wShowWindow = subprocess.SW_HIDE proc = subprocess.Popen(...,startupinfo = info) 这在某种程度上有效,但不能递归地工作。即如果 启动进程本身启动一个窗口,那第二个窗口将不会隐藏。这甚至适用于应用程序中的对话框。所以 而不是很多窗口弹出我现在得到了很多无实体的 对话框出现,这是一个小小的改进,但并不多。 此外,某些进程(例如tkdiff)似乎忽略了完全隐藏 的指令。 这在UNIX上很容易实现使用Xvfb等虚拟显示器。如果有人可以在Windows上从python中获取任何光线吗? 问候, Geoff Bache 解决方案 我很困惑。如果你不打算创建GUI,为什么要创建一个GUI?b $ b实际显示它?这不是GUI的重点吗?或者你正在谈论 关于弹出的命令窗口? Mike 我'我很困惑。如果你不打算创建GUI,为什么要创建一个GUI?b $ b实际显示它?这不是GUI的重点吗?或者你在谈论 关于弹出的命令窗口? Mike 仅限于测试它的背景。如果我在我的 计算机上运行了很多GUI测试,我想要 测试的GUI保持隐藏状态,这样我仍然可以在 $ b $中使用我的电脑同时... 虽然你能告诉我如何停止弹出命令窗口 Windows 我我也很感激(虽然这不是原来的问题)。 Geoff 仅在测试环境中。如果我在我的 计算机上运行了很多GUI测试,我想要 测试的GUI保持隐藏状态,这样我仍然可以在 $ b $中使用我的电脑同时... 虽然你能告诉我如何停止弹出命令窗口 Windows 我我也很感激(虽然这不是原来的问题)。 Geoff 您使用的是哪种GUI工具包? Tkinter,wxPython,pyQt?至于 在Windows上丢失命令窗口,我知道的最好的方法是将的扩展名从* .py更改为 * .pyw。我很确定你可以压缩命令窗口,如果你是使用一个标志从命令行调用它们,但是我不记得 我最喜欢的标志。 在能够使用计算机的同时进行测试的一种方法是使用VMWare或某些软件来安装虚拟机类似的产品。我使用了 VMWare的免费软件来测试我的一些脚本,但是我听说过微软有一个免费的虚拟产品。一半不好。 迈克 Hi,As part of my efforts to write a test tool that copes with GUIsnicely, I''m trying to establish how I can start a GUI process onWindows that will not bring up the window. So I try to hide the windowas follows:info = subprocess.STARTUPINFO()info.dwFlags |= subprocess.STARTF_USESHOWWINDOWinfo.wShowWindow = subprocess.SW_HIDEproc = subprocess.Popen(..., startupinfo=info)This works, in a way, but doesn''t work recursively. I.e. if thestarted process itself starts a window, that second window will not behidden. This even applies to dialog boxes within the application. Soinstead of a lot of windows popping up I now get a lot of disembodieddialogs appearing, which is a slight improvement but not much.Also, certain processes (e.g. tkdiff) seem to ignore the directive tobe hidden altogether.This is dead easy on UNIX with virtual displays like Xvfb. Can someoneshed any light if it''s possible on Windows from python?Regards,Geoff Bache 解决方案I''m confused. Why would you create a GUI if you''re not going toactually display it? Isn''t that the point of a GUI? Or are you talkingabout the command window popping up?MikeI''m confused. Why would you create a GUI if you''re not going toactually display it? Isn''t that the point of a GUI? Or are you talkingabout the command window popping up?MikeOnly in the context of testing it. If I run lots of GUI tests on mycomputer I wantthe tested GUIs to remain hidden so I can still use my computer in themeantime...Though if you can tell me how to stop the command window popping up onWindowsI''ll be grateful for that too (though it wasn''t the originalquestion).GeoffOnly in the context of testing it. If I run lots of GUI tests on mycomputer I wantthe tested GUIs to remain hidden so I can still use my computer in themeantime...Though if you can tell me how to stop the command window popping up onWindowsI''ll be grateful for that too (though it wasn''t the originalquestion).GeoffWhich GUI toolkit are you using? Tkinter, wxPython, pyQt? As forlosing the command window on Windows, the best way that I know of isto just change the extension of the python file itself from *.py to*.pyw . I''m pretty sure you can suppress command windows if you''recalling them from the command line using a flag, but I can''t recallthe flag off the top of my head.One way to test while still being able to use your computer is toinstall a virtual machine with VMWare or some similar product. I useVMWare''s free software for testing some of my scripts, but I''ve heardthat Microsoft''s got a free virtual product that isn''t half bad.Mike 这篇关于使子进程在Windows上隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 18:19