472,127 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Getting subprocesses to be hidden on Windows

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

Aug 27 '07 #1
11 5602
On Aug 27, 3:21 pm, geoffbache <geoff.ba...@pobox.comwrote:
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
I'm confused. Why would you create a GUI if you're not going to
actually display it? Isn't that the point of a GUI? Or are you talking
about the command window popping up?

Mike

Aug 27 '07 #2
On Aug 27, 11:28 pm, kyoso...@gmail.com wrote:
On Aug 27, 3:21 pm, geoffbache <geoff.ba...@pobox.comwrote:
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

I'm confused. Why would you create a GUI if you're not going to
actually display it? Isn't that the point of a GUI? Or are you talking
about the command window popping up?

Mike
Only in the context of testing it. If I run lots of GUI tests on my
computer I want
the tested GUIs to remain hidden so I can still use my computer in the
meantime...

Though if you can tell me how to stop the command window popping up on
Windows
I'll be grateful for that too (though it wasn't the original
question).

Geoff

Aug 28 '07 #3
On Aug 28, 4:08 am, geoffbache <geoff.ba...@pobox.comwrote:
On Aug 27, 11:28 pm, kyoso...@gmail.com wrote:
On Aug 27, 3:21 pm, geoffbache <geoff.ba...@pobox.comwrote:
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
I'm confused. Why would you create a GUI if you're not going to
actually display it? Isn't that the point of a GUI? Or are you talking
about the command window popping up?
Mike

Only in the context of testing it. If I run lots of GUI tests on my
computer I want
the tested GUIs to remain hidden so I can still use my computer in the
meantime...

Though if you can tell me how to stop the command window popping up on
Windows
I'll be grateful for that too (though it wasn't the original
question).

Geoff
Which GUI toolkit are you using? Tkinter, wxPython, pyQt? As for
losing the command window on Windows, the best way that I know of is
to just change the extension of the python file itself from *.py to
*.pyw . I'm pretty sure you can suppress command windows if you're
calling them from the command line using a flag, but I can't recall
the flag off the top of my head.

One way to test while still being able to use your computer is to
install a virtual machine with VMWare or some similar product. I use
VMWare's free software for testing some of my scripts, but I've heard
that Microsoft's got a free virtual product that isn't half bad.

Mike


Aug 28 '07 #4
Which GUI toolkit are you using? Tkinter, wxPython, pyQt?
Primarily PyGTK, but I was hoping it wouldn't matter. I hope to be
able
to start the process as indicated in the original post from within my
test
tool and instruct the subprocess to be hidden (or minimized? would
that be easier?),
irrespective of what it was (it might be a Java GUI or anything for
all I care...)
As for
losing the command window on Windows, the best way that I know of is
to just change the extension of the python file itself from *.py to
*.pyw . I'm pretty sure you can suppress command windows if you're
calling them from the command line using a flag, but I can't recall
the flag off the top of my head.
Thanks, that seemed to work.
One way to test while still being able to use your computer is to
install a virtual machine with VMWare or some similar product. I use
VMWare's free software for testing some of my scripts, but I've heard
that Microsoft's got a free virtual product that isn't half bad.
OK. If all else fails I might try that. But if there is a solution to
the original
problem it would be nice not to have to install VMWare everywhere for
convenient testing...

Geoff
Aug 28 '07 #5
On Aug 28, 8:59 am, geoffbache <geoff.ba...@pobox.comwrote:
Which GUI toolkit are you using? Tkinter, wxPython, pyQt?

Primarily PyGTK, but I was hoping it wouldn't matter. I hope to be
able
to start the process as indicated in the original post from within my
test
tool and instruct the subprocess to be hidden (or minimized? would
that be easier?),
irrespective of what it was (it might be a Java GUI or anything for
all I care...)
As for
losing the command window on Windows, the best way that I know of is
to just change the extension of the python file itself from *.py to
*.pyw . I'm pretty sure you can suppress command windows if you're
calling them from the command line using a flag, but I can't recall
the flag off the top of my head.

Thanks, that seemed to work.
One way to test while still being able to use your computer is to
install a virtual machine with VMWare or some similar product. I use
VMWare's free software for testing some of my scripts, but I've heard
that Microsoft's got a free virtual product that isn't half bad.

OK. If all else fails I might try that. But if there is a solution to
the original
problem it would be nice not to have to install VMWare everywhere for
convenient testing...

Geoff
I did a quick google and found the following, which probably only
applies to Windows:

http://www.tech-recipes.com/windows_tips512.html

I know that with wxPython, you can tell it to whether or not to show
the frame. Maybe pyGTK has the same functionality? This link seems to
suggest that that maybe a valid option, but it doesn't detail how to
accomplish it:

http://www.daa.com.au/pipermail/pygt...st/000300.html

This might be better: http://linuxgazette.net/issue78/krishnakumar.html

Looks to me like you could just omit the "show" method. However, I
have never used that particular toolkit. When you run stuff hidden
like that, it can be difficult to kill them.

Mike

Aug 28 '07 #6
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
Aug 28 '07 #7

OK, more background needed. I develop the TextTest tool which is a
generic test tool that starts tested applications from
the command line. The idea is that it can handle any system under test
at all, whatever language it's written in. Preferably
without requiring a bunch of changes to the tested code before
starting. I'd like to be able to pass some sort of flag to
ensure that the system under test *and everything it starts* remain
hidden.

I can do as you suggest in my PyGTK GUI, of course, but that's only
one system under test. A generic solution, if there
is one, would be much better. I felt like there ought to be one
because :

a) It's easy on UNIX and
b) I managed to hide the system under test fairly easily, just not its
child windows and dialogs.

Thanks for the help, anyway, it's another fallback if I can't find a
solution.

Aug 28 '07 #8
On 28 Aug, 18:18, Larry Bates <larry.ba...@websafe.comwrote:
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

Aug 28 '07 #9

geoffbache wrote:
On 28 Aug, 18:18, Larry Bates <larry.ba...@websafe.comwrote:
>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
You might want to look into running the tests on a separate desktop (or possibly
even a new window station).

Roger
Aug 29 '07 #10
On Aug 28, 1:13 pm, geoffbache <geoff.ba...@pobox.comwrote:
On 28 Aug, 18:18, Larry Bates <larry.ba...@websafe.comwrote:
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/...cess-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

Aug 29 '07 #11
geoffbache wrote:
As part of my efforts to write a test tool that copes with GUIs
This is dead easy on UNIX with virtual displays like Xvfb.
Can someone shed any light if it's possible on Windows
Configure the virtual display first:
http://en.wikipedia.org/wiki/Virtual_desktop

Alternatively, run the process in a separate gui.
Terminal Server client is one way to do that.

[david]
Sep 3 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jane Austine | last post: by
2 posts views Thread by Marcos | last post: by
11 posts views Thread by Ray Muforosky | last post: by
2 posts views Thread by Dave Kirby | last post: by
5 posts views Thread by Adam Clauss | last post: by
3 posts views Thread by Dara Durum | last post: by
1 post views Thread by Gal Diskin | last post: by
reply views Thread by shinichi81 | last post: by
reply views Thread by =?Utf-8?B?aXdkdTE1?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.