Get terminal size in perl and python

Donn Cave donn at u.washington.edu
Thu Mar 8 17:42:21 EST 2001


Quoth grante at visi.com (Grant Edwards):
[ ... vs. COLUMNS and LINES ]
| In most Unixes you'd be better off using the ioctl() call (the
| details of which I can't remember at the moment -- I thought it
| was in the termios struct, but I can't find it).

It has its own struct, and its own ioctls:

>>> x = fcntl.ioctl(0, 0x40087468, '12345678')
>>> struct.unpack('hhhh', x)
(24, 80, 240, 800)

The symbol would be TIOCGWINSZ, if you have it, but I don't think
that many do.  0x40087468 is good for NetBSD 1.5.  I don't see any
value for LINES or COLUMNS, and I'm not surprised - I think of that
as more of a SysV 3.2 thing than Berkeley.  But it really depends
on how you got there - ssh/telnet/console login, bash/ksh/csh, etc.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list