[python-win32] win32console attach problems
Stian
stian.prg at gmail.com
Fri Oct 3 21:14:08 CEST 2008
Hi,
I'm experiencing concurring problems when attempting to attach to a console
using the PyWin32 win32console. I have an application which may attach to a
console, send ctrl+c to it and then detach - using win32console. If I do
this "too soon" after the console is started the AttachConsole fails,
throwing an exception. Fair enough. My issue is that after one such a
failing attempt all following AttachConsole attempts will fail the same way.
My first thought was that perhaps it is somewhat attached even though it
fails. So I put in a call to FreeConsole to be called each time before
AttachConsole – in a different try-except clause. No luck. So; any ideas why
am I unable to attach to this console when I know it has started up properly
- just because it failed once? If I don't get one early failing attempt all
the win32console functions runs like a charm each time.
Here is a simplified variant of my function:
def my_func(self):
try:
win32console.FreeConsole()
except:
pass
try:
win32console.AttachConsole(pid)
win32console.GenerateConsoleCtrlEvent(
win32console.CTRL_C_EVENT, pid
)
win32console.FreeConsole()
except:
show_error_messagebox(ERROR_MESSAGE_ON_CONSOLE_SHUTDOWN)
return False
Any comments are welcome.
Regards,
Stian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20081003/e1d64c5a/attachment.htm>
More information about the python-win32
mailing list