Why doesn't this work ? (Simple pexpect code)

2009-01-30
2013-03-15
  • armdeveloper

    armdeveloper - 2009-01-30

    I'm trying to build a small Python app in Eclipse under Fedora 10.

    I have the following code:

    import os
    import sys
    import pexpect

    child = pexpect.spawn('/bin/bash')
    child.interact()

    When I run it in Eclipse, I get:

    Traceback (most recent call last):
      File "/home/xxx/workspace/FixPermissions/src/default/main.py", line
    56, in <module>
        child.interact()
      File "/usr/lib/python2.5/site-packages/pexpect.py", line 1489, in
    interact
        mode = tty.tcgetattr(self.STDIN_FILENO)
    termios.error: (22, 'Invalid argument')

    Yet if I run it in a bash shell, it works:

    $ python
    Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
    [GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> import sys
    >>> import pexpect
    >>> child = pexpect.spawn('/bin/bash')
    >>> child.interact()
    [xxx@localhost ~]$ ls
                    <outputs file list here...>
    [xxx@localhost ~]$ exit
    >>>
    >>>

    Why doesn't it run under Eclipse and how do I fix it so it does ?

    Thanks

    BTW: pydev rocks !

     
    • Fabio Zadrozny

      Fabio Zadrozny - 2009-02-01

      This doesn't work because Eclipse is not able to give you a 'real' shell. It just spawns your process as a regular process from java and hears its stdin/stdout and stderr (that's not likely to change from Pydev, although maybe the guys at eclipse can do something about it... it's the same bug from using the System.Console that doesn't work in jdk 6: https://bugs.eclipse.org/122429 )

      So, you should be able to do all the developing from pydev, but you must run it in a separate shell (and to debug use the remote debugger -- only in pydev extensions: http://fabioz.com/pydev/manual_adv_remote_debugger.html )

      Cheers,

      Fabio