[python-win32] win32console attach problems

Stian stian.prg at gmail.com
Sun Oct 5 15:16:37 CEST 2008


> Well, let me ask a silly question.  Are you running this from a "pyw"
> app, using Pythonw.exe, so you don't have a console of your own?

Well, that's not a silly question for me - I'm rather new to Python. Anyway
- let me tell you a bit more about how this is put together if that may be
relevant.
I have a GUI written with wxWidgets/wxPython. A .exe-file is created using
pyinstaller. I don't think pyw is explicitly used, but I see something about
pythonw in the pyinstaller files. Perhaps this is used here? My GUI starts a
console using win32process like this:

win32process.CreateProcess(None, exe_path, None,
  None, False, win32con.CREATE_NEW_PROCESS_GROUP |
  win32con.CREATE_NEW_CONSOLE, None, None, startupinfo)

And at a later point - clicking one of the buttons in the GUI - it should
kill this console using the mentioned code:

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


Does this make it any clarify what may be wrong?
Thanks for your time!

Stian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20081005/8af996a6/attachment.htm>


More information about the python-win32 mailing list