STDOUT truncation

Operating system - Solaris 8, Korn shell, xterm

Command
/usr/proc/bin/ptree [PID]
outputs the process tree exactly as I want with all detail

However,
/usr/proc/bin/ptree [PID] | more
truncates the process descriptions at an 80 character point. If the process tree has marched enough to the right, I see no description at all - but I still see the PID

So does
/usr/proc/bin/ptree [PID] > tmp_file

So does
ksh > tmp_file
/usr/proc/bin/ptree [PID]

I've tried all sorts of things to redirect the output but nothing wants to work - what's happening to STDOUT when it's being redirected in any way?

I really hate programs like that. "ls" is another one. In a directory with a lot of files, try "ls" and then "ls|cat". The program is inspecting stdout and it behaves differently depending on whether it is a tty device or not.

Looking at the source code for ptree, we see

     87 static	int	columns = 80;
.
.
.
    159 	/*
    160 	 * Kind of a hack to determine the width of the output...
    161 	 */
    162 	if ((s = getenv("COLUMNS")) != NULL && (n = atoi(s)) > 0)
    163 		columns = n;
    164 	else if (isatty(fileno(stdout)) &&
    165 	    ioctl(fileno(stdout), TIOCGWINSZ, &winsize) == 0 &&
    166 	    winsize.ws_col != 0)
    167 		columns = winsize.ws_col;

"Kind of a hack"??? Well, anyway, set the COLUMNS environment variable to the size you want. It's disappointing that behavior like this is not mentioned in the man page, but making the source code available really picks up the slack

Brilliant. Thanks very much - works a treat! This was starting to bug me!

Hi,

Output of running berkeley ps is still truncated to 80 chars. getting longer lines is done by changing the stty
$ stty columns 300
$ /usr/ucb/ps -e 12490
PID TT S TIME COMMAND
12490 pts/24 S 0:00 sleep 4000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...#line is 300 char

trying to get the total length

$ set COLUMNS=300;export COLUMNS
$ echo $COLUMNS
300
$ /usr/ucb/ps -e 12490|cat #truncated to 80 chars
PID TT S TIME COMMAND
12490 pts/24 S 0:00 sleep 4000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Does some knows how to overcome this problem?
How can i know what is the max size the stty columns can be define?

I have noticed that setting the stty columns higher the the length of the command and arguments (ps -e) the ps "command" line shows only the process name in brackets e.g. [java].
Thats why i am looking for the max size of the command and args.

Thanks in advance