Problem while doing a cat on a tabbed file with pexpect

Saqib Ali saqib.ali.75 at gmail.com
Sun Jan 15 12:51:44 EST 2012


I am using Solaris 10, python 2.6.2, pexpect 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")
>>> x.sendline("cat me.txt")
11
>>> x.expect([pexpect.TIMEOUT, "% "])
1
>>> x.before
'cat me.txt\r\r\nA       B       C\r\n'
>>> x.before.split("\t")
['cat me.txt\r\r\nA       B       C\r\n']



Now, clearly the file contains tabs. But when I cat it through expect,
and collect cat's output, those tabs have been converted to spaces.
But I need the tabs!

Can anyone explain this phenomenon or suggest how I can fix it?



More information about the Python-list mailing list