问题
Python 2.7
OS: Windows (program will ALWAYS work on Windows so cross compatibility isn't an issue )
I'm forced to use external application as a part of an validation process and i'm having troubles hidding the popup windows which come as an output of this external program.
Basically i do this:
args = [ "-A" + param_a, "-B" + param_b, "-C" + param_c ]
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess._subprocess.SW_HIDE
process = Popen(["C:\external_app.exe", args[0],args[1],args[2]], startupinfo=startupinfo, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(output, err) = process.communicate()
exit_code = process.wait()
print exit_code
The code works, but when there is an missing parameter, or parameters are not valid, the external program outputs a popup window with a corresponding message and an "OK" button, that needs to be clicked on to continue.
In the code I also included all my attemps to prevent that from happening.
I know there must be a way to disable this behaviour, because program can work as independent windows task and isn't interrupted by any of these messages.
Maybe there is a way of emulating this in Python or in Windows itself ? Or perhaps there is a way to auto-confirm all incomming dialog-popups of an application?
Any solution would do.
Thanks, Piotr
PS. I also tried contacting original author of this app but the company isn't even there... Also tried to guess an optional parameter like -hidden etc. but without any luck.
来源:https://stackoverflow.com/questions/20047245/python-windows-prevent-subprocess-external-program-from-displaying-popups