From: James Edward Gray II Date: 2007-08-08T06:55:27+09:00 Subject: Re: Need Solaris Help On Aug 7, 2007, at 4:23 PM, Daniel Berger wrote: > > > On Aug 7, 2:10 pm, James Edward Gray II > 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. It's this magic number work that scares me. In fact, the entire chunk of code above is pretty opaque to me. On the flip size, I understand exactly what the stty code does and how it works. If it someone complains that it's broken on HP-UX, AIX, or their POSIX-compliant toaster, we will add another branch in the if chain. I don't see that as any more maintenance than finding the magic number and I know how to ask users to help me do the former. Ronald parsed the output for Solaris with a single trivial Regexp, so that didn't feel like a significant hurdle to me. In short, I'm comfortable with the stty approach. So far I haven't seen it blow up in anyway that I feel we would escape using ioctl(). Thanks for the advice though. James Edward Gray II