Problem while doing a cat on a tabbed file with pexpect
steve+comp.lang.python at pearwood.info
Sun Jan 15 21:01:35 EST 2012
On Sun, 15 Jan 2012 09:51:44 -0800, Saqib Ali wrote:
> I am using Solaris 10, python 2.6.2, pexpect 2.4
Are you sure about that? As far as I can see, pexpect's current version
is 2.3 not 2.4.
> I create a file called me.txt which contains the letters "A", "B", "C"
> on the same line separated by tabs.
> My shell prompt is "% "
> I then do the following in the python shell:
>>>> import pexpect
>>>> x = pexpect.spawn("/bin/tcsh")
Can you try another shell, just in case tcsh is converting the tabs to
>>>> x.sendline("cat me.txt")
What happens if you do this from the shell directly, without pexpect? It
is unlikely, but perhaps the problem lies with cat rather than pexpect.
You should eliminate this possibility.
>>>> x.expect([pexpect.TIMEOUT, "% "])
> 'cat me.txt\r\r\nA B C\r\n'
Unfortunately I can't replicate the same behaviour, however my setup is
different. I'm using pexpect2.3 on Linux, and I tried it using bash and
sh but not tcsh. In all my tests, the tabs were returned as expected.
(However, the x.expect call returned 0 instead of 1, even with the shell
prompt set correctly.)
More information about the Python-list