Getting subprocesses to be hidden on Windows

kyosohma at gmail.com kyosohma at gmail.com
Wed Aug 29 09:31:57 EDT 2007


On Aug 28, 1:13 pm, geoffbache <geoff.ba... at pobox.com> wrote:
> On 28 Aug, 18:18, Larry Bates <larry.ba... at websafe.com> wrote:
>
>
>
> > geoffbache wrote:
> > > Hi,
>
> > > As part of my efforts to write a test tool that copes with GUIs
> > > nicely, I'm trying to establish how I can start a GUI process on
> > > Windows that will not bring up the window. So I try to hide the window
> > > as follows:
>
> > > info = subprocess.STARTUPINFO()
> > > info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
> > > info.wShowWindow = subprocess.SW_HIDE
>
> > > proc = subprocess.Popen(..., startupinfo=info)
>
> > > This works, in a way, but doesn't work recursively. I.e. if the
> > > started process itself starts a window, that second window will not be
> > > hidden. This even applies to dialog boxes within the application. So
> > > instead of a lot of windows popping up I now get a lot of disembodied
> > > dialogs appearing, which is a slight improvement but not much.
>
> > > Also, certain processes (e.g. tkdiff) seem to ignore the directive to
> > > be hidden altogether.
>
> > > This is dead easy on UNIX with virtual displays like Xvfb. Can someone
> > > shed any light if it's possible on Windows from python?
>
> > > Regards,
> > > Geoff Bache
>
> > While I'm not entirely sure I understand what you want, I think you can
> > accomplish it by using win32CreateProcess instead of subprocess.  You can run
> > the application minimized or perhaps in a REALLY small window.  If you have
> > modal dialog boxes, I don't think you can do anything as they don't run in the
> > parent windows frame but rather outside (I could be wrong about this).
>
> > -Larry
>
> Hi Larry,
>
> I don't know if that would help. I've tried running minimized from the
> command line as
> suggested by Mike and that has the same issue (child windows and
> dialogs don't get minimized)
> So the question is moving away from how to technically achieve this in
> Python to whether
> Windows even supports it...
>
> Geoff

I just discovered Tim Golden's recipe for running processes minimized:
http://tgolden.sc.sabren.com/python/wmi_cookbook.html#run-process-minimised

I haven't tested it, but his stuff usually works. However, it may have
the same issues with modal dialogs that my other suggestion had.

Mike




More information about the Python-list mailing list