Getting subprocesses to be hidden on Windows

G

geoffbache

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
 
K

kyosohma

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
 
G

geoffbache

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
 
K

kyosohma

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
 
G

geoffbache

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
 
K

kyosohma

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...)


Thanks, that seemed to work.


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/pygtk/2000-August/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
 
L

Larry Bates

geoffbache said:
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
 
G

geoffbache

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.
 
G

geoffbache

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
 
R

Roger Upole

geoffbache said:
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
 
K

kyosohma

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top