[python-win32] wexpect and running without a console

Olof Rutgersson Olof.Rutgersson at xelerated.com
Wed Jan 20 15:57:53 CET 2010


Hello

I'm using wexpect to access various programs such as plink, cygwin and other command line tools in windows. The code works fine when the python interpreter is launched from a console window, but when I launch it through any other process (for instance, a scheduler for automation of certain tasks) I get an exception. The spawn call for creating a child process to the python process works (and really does spawn the child process), but as soon as I do an expect() call the following exception occurs:

   File "...\expect\wexpect.py", line 1330, in expect
     return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
   File "...\expect\wexpect.py", line 1344, in expect_list
     return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
   File "...\expect\wexpect.py", line 1397, in expect_loop
     c = self.read_nonblocking (self.maxread, timeout)
   File "...\expect\wexpect.py", line 1771, in read_nonblocking
     s = self.wtty.read_nonblocking(timeout, size)
   File "...\expect\wexpect.py", line 2149, in read_nonblocking
     self.switchBack()
   File "...\expect\wexpect.py", line 1975, in switchBack
     FreeConsole()
 error: (87, 'FreeConsole', 'The parameter is incorrect.')

A closer look reveals that line 2149 is the exception handling of another error thrown:
Traceback (most recent call last):
  File "...\expect\wexpect.py", line 2135, in read_nonblocking
    self.switchBack()
  File "...\expect\wexpect.py", line 1976, in switchBack
    AttachConsole(self.__parentPid)
error: (6, 'AttachConsole', 'The handle is invalid.')

The invalid handle error seems to be related to the fact that I'm not launching python.exe from a console but from another process, can it be related to issue 1124861 (http://bugs.python.org/issue1124861)? Do I need to create different stdin and stdout or spawn the child process in any other way from wexpect? Are there any other ways of solving this problem?

The wexpect code used can be found at: http://wstein.org/home/goreckc/sage/wexpect/wexpect.py

If this is not the correct mailing list, I apologize and hope that you can show me where to post my question.

Olof Rutgersson
System Test Engineer

Xelerated AB
Olof Palmes Gata 29
SE-111 22 Stockholm
Sweden






More information about the python-win32 mailing list