STDOUT truncation


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users STDOUT truncation
# 1  
Old 11-29-2006
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?
# 2  
Old 11-29-2006
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
Code:
     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
# 3  
Old 11-30-2006
Brilliant. Thanks very much - works a treat! This was starting to bug me!
# 4  
Old 12-03-2006
Still there is a problem - ps - Is it Magic?

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Space truncation

HI All- We have script like the followinga='h1 ' b='12434 ' c=' fagkasdbkZ<M' output=$a$b$c echo $output > /home/dsomasun/fil_concat.txtBut in the output file spaces are truncated and Output is coming like the belowh1 1234 fagkasdbkZ<M please advise Please wrap all code,... (4 Replies)
Discussion started by: dhilipans1988
4 Replies

2. UNIX for Dummies Questions & Answers

STDout

Hi, I have a program set to read in a text file, change certain characters and then print the altered version to the screen but does anyone know how to save the new version as another text file? And, if possible, how to specify the file name, and perhaps location? Thanks! (2 Replies)
Discussion started by: PerlNutt
2 Replies

3. UNIX for Advanced & Expert Users

Truncation Occurs When Outputting Shell Script to stderr

Operating System: Solaris 10, Shell We are outputting the results of our scripts to the stderr file. However we have encountered a problem where some of the lines in the file are truncated. Is there a way to increase the terminal or column size within the script so that this does not... (4 Replies)
Discussion started by: fazzasx
4 Replies

4. Filesystems, Disks and Memory

SCO 5.6 + file truncation

Sir, my apologies for I had put this question in a different forum earlier. I am running an appliction in SCO 5.6. If the records are more than one lakh, the output file is getting truncated to one lakh. Please help me in rectifying the issue whereby it allows creation of output with more than... (0 Replies)
Discussion started by: chssastry
0 Replies

5. Post Here to Contact Site Administrators and Moderators

SCO 5.6 File truncation

Sir, my apologies for not being able to correspond for a long time. I am running an appliction in SCO 5.6. If the records are more than one lakh, the output file is getting truncated to one lakh. Please help me in rectifying the issue whereby it allows creation of output with more than one lakh... (0 Replies)
Discussion started by: chssastry
0 Replies

6. UNIX for Advanced & Expert Users

Syslog Truncation / Size Limit?

I searched and could not find an answer to this, and am having difficulty, so I would appreciate any assistance that can be offered. We're experiencing logs that are having all characters after the 850th one written being truncated. I am wondering if there is a default limit to the syslog... (1 Reply)
Discussion started by: Puck
1 Replies

7. AIX

PS output truncation in AIX

folks; i need help with a truncation problem in AIX when running "ps" command. when i run ps in SUN, i got the full output but when i run it in AIX the output is truncated. is there any arguments i can pass to give longer output so i can overcome the issue? here's the details:(please note the... (2 Replies)
Discussion started by: moe2266
2 Replies

8. UNIX for Advanced & Expert Users

What is the cause of file truncation?

Hi, I have a program that gets called from the front end of my application. Actually it creates some temporary files and uses them and deletes them at last. But sometimes, say once in 6 times, some of these temporary files are getting truncated in the middle and because of this my program is... (9 Replies)
Discussion started by: venkatmyname
9 Replies

9. UNIX for Advanced & Expert Users

truncation when vi a file

Hi, I'm using the vi that comes with Solaris 2.8. When vi a file with lines that have long continuous characters e.g. more than 256 chars, these lines got truncated. This is a known limitation of the out of the box Solaris vi, and there is a suggestion to get another vi. Is there an... (0 Replies)
Discussion started by: selur-xinu
0 Replies

10. Solaris

solaris 2.5.1 /usr/ucb/ps truncation problems

we aheva couple of old sun OS boxes, that we are trying to parse /usr/ucb/ps output. However it seems that something is occuring that is causeing th output of "/usr/ucb/ps -auxwww" to cut short the process name, whereas "ps -eaf" can display the entire process name. It will work for a while... (2 Replies)
Discussion started by: adralph
2 Replies
Login or Register to Ask a Question