On Aug 7, 2:10 pm, James Edward Gray II <ja... / grayproductions.net>
wrote:
> On Aug 7, 2007, at 3:04 PM, Daniel Berger wrote:
>
> > I think you're better off using this snippet that Greg Hurrell showed
> > you earlier this year instead of shelling out at all. I've modified it
> > to use the correct value of TIOCGWINSZ for Solaris:
>
> > TIOCGWINSZ = 21608
> > buf = [0, 0, 0, 0].pack('SSSS')
> > if $stdin.ioctl(TIOCGWINSZ, buf) >= 0
> >   rows, cols, xpixels, ypixels = buf.unpack("SSSS")
> >   p rows, cols, xpixels, ypixels
> > else
> >   puts "Unable to get window size"
> > end
>
> Can you explain why you feel the above is "better?"

Because the output is predictable and therefore more reliable. It also
doesn't require forking off a new process.

I've no idea if the output from 'stty -a' is the same from Solaris
2.5.1 through Solaris 10. Also, have you verified that shelling out to
stty returns the output you expect on other platforms such as HP-UX or
AIX?

Mind you, this approach requires figuring out the appropriate value
for TIOCGWINSZ for each platform (which probably doesn't change
between releases), but that's easier than parsing stdout for each
platform IMHO.

Just my .02.

Regards,

Dan