Strange pexpect behaviour: just duplicates stdin

N

Nikolaus Rath

Hello,

I have a strange problem with pexpect:

$ cat test.py
#!/usr/bin/python

import pexpect

child = pexpect.spawn("./test.pl")

while True:
try:
line = raw_input()
except EOFError:
break

child.sendline(line)
print child.readline().rstrip("\r\n")

child.close()

$ cat test.pl
#!/usr/bin/perl
# Replace all digits by __
while (<>) {
s/[0-9]+/__/g;
print;
}

$ echo bla24fasel | ./test.pl
bla__fasel

$ echo bla24fasel | ./test.py
bla24fasel


Why doesn't the last command return bla__fasel too?


I extracted this example from an even stranger problem in a bigger
program. In there, pexpect sometimes returns both the string send with
sendline() *and* the output of the child program, sometimes the
correct output of the child, and sometimes only the input it has send
to the child. I couldn't figure out a pattern, but the above example
always produces the same result.


Anyone able to help?


Best,

-Nikolaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top