Problem while doing a cat on a tabbed file with pexpect
cs at zip.com.au
Sun Jan 15 20:45:35 EST 2012
On 15Jan2012 16:14, Saqib Ali <saqib.ali.75 at gmail.com> wrote:
| The file me.txt does indeed contain tabs. I created it with vi.
| >>> text = open("me.txt", "r").read()
| >>> print "\t" in text
| % od -c me.txt
| 0000000 A \t B \t C \n
| % ls -al me.txt
| -rw-r--r-- 1 myUser myGroup 6 Jan 15 12:42 me.txt
Ok, your file does indeed contain TABs.
Therefre something is turning the TABs into spaces. Pexpect should be
opening a pty and reading from that, and I do not expect that to expand
1: Using subprocess.Popen, invoke "cat me.txt" and check the result
2: Using pexpect, run "cat me.txt" instead of "/bin/tcsh" (eliminates a
layer of complexity; I don't actually expect changed behaviour) and
check for TABs.
On your Solaris system, read "man termios". Does it have an "expand
TABs" mode switch? This is about the only thing I can think of that
would produce your result - the pty terminal discipline is expanding
TABs for your (unwanted!) - cat is writing TABs to the terminal and the
terminal is passing expanded spaces to pexpect. Certainly terminal line
disciplines do rewrite stuff, most obviously "\n" into "\r\n", but a
quick glance through termios on a Linux box does not show a tab
expansion mode; I do not have access to a Solaris box at present.
Cameron Simpson <cs at zip.com.au> DoD#743
Maintainer's Motto: If we can't fix it, it ain't broke.
More information about the Python-list