I'm trying to determine the terminal window from within a TCL script.
I was playing around with Linux's 'tput cols' and get strange
differences between using and not using exec:
% tput cols
153 (correct)
% exec tput cols
80 (incorrect)
So, ok, I got the right answer, but that works only for interactive
shell; in a script I get invalid command tput.
So:
1. How can I get exec tput to behave as tput, or;
2. How do I determine the terminal width from within a TCL script?
set width [lindex [exec stty size] 1]
Use [exec tput cols >@ stdout].
The reason is that without the >@ redirection, Tcl uses a pipe reading
from the child's stdout (to produce [exec]'s result). Hence tput's
ioctl()s operate on the pipe, which gets a default geometry unrelated
to the surrounding terminal.
> 2. How do I determine the terminal width from within a TCL script?
Now, the problem is that you _also_ want the script to get at the
value :}
It turns out that tputs is an utterly stupid tool, designed to be used
only be human eyes: it queries fd 1, *and* writes the info to it !
As you found out, stty is smarter, in that it does its ioctl() on fd
0. This explains why it works in [exec], which has an implicit "<@
stdin" (no redirection needed).
-Alex