program I feed in interactively as below

http://pastebin.com/qGHMiHjp

child.before contains the expected data (output of expect command)

I run the code as python progname.py: (code shown below example run on pastebin)

http://pastebin.com/AWY0vM88

import pexpect
import sys
child = pexpect.spawn('gdb',logfile=sys.stdout)
try:
child.expect(pexpect.EOF,timeout=0)
except Exception, e:
print child.before
import code;code.interact(local=locals())

and child.before is null

Why is that? I would expect that commands fed in interactively would produce the same
results as a program run by python progname.py

The import code; code.interact(local=locals()) is there to get me into the python
shell to play around

print child.before in the program produces nothing -- it should produce the output of the gdb command

I am using child.expect(pexpect.EOF,timeout=0) because I want the immediate output of
any command that I produce without looking for carriage return/lf etc or the prompt of a command

anyone?

Recommended Answers

All 2 Replies

I added a small sleep() and it worked ! why ? I DONT KNOW :)

import pexpect
import sys
import code
from time import sleep

child = pexpect.spawn('gdb', logfile = sys.stdout)
sleep(0.3)
try:
    child.expect(pexpect.EOF,timeout=0)
except Exception, e:
    print child.before
    
code.interact(local=globals())

""" my output -->
GNU gdb (GDB) 7.1-1mdv2010.1 (Mandriva Linux release 2010.1)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-mandriva-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) GNU gdb (GDB) 7.1-1mdv2010.1 (Mandriva Linux release 2010.1)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-mandriva-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) 
Python 2.6.5 (r265:79063, May 20 2011, 13:36:15) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> 
"""

(Also, learn about code tags, etc in the sitcky thread 'Read This Before Posting' above)

> I added a small sleep() and it worked ! why ? I DONT KNOW

OK thanks. must be because perspect module is slow - update slow

ditched it anyway - was only looking at it because I couldn't get paramiko to work again
paramiko I have got working again now - much more functionality

was looking around - twisted conch - perspect -- perspect seems very basic

have avoided twisted so far because it seems like overkill a huge contraption

lots of great smaller modules to to specific things -- like paramiko

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.