Strange pexpect behaviour: just duplicates stdin
Nikolaus Rath
Nikolaus at rath.org
Mon Mar 30 21:23:40 EDT 2009
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
--
»Time flies like an arrow, fruit flies like a Banana.«
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
More information about the Python-list
mailing list