Search code examples
unixsolaris

/usr/ucb/ps output redirection yield truncated line


/usr/ucb/ps command output to screen shows a long list envrionment variable and its values, but when redirecting output to a file yields a truncated line.

How to explain this?

bash-3.2$ /usr/ucb/ps -auxwee 6543 >/var/tmp/env-var 2>&1

bash-3.2$ cat /var/tmp/env-var
USER       PID %CPU %MEM   SZ  RSS TT       S    START  TIME COMMAND
alcrprun  6543  0.0  0.0 8752 5992 ?        S 19:35:01  0:15 /usr/bin/python -Bu ./bin/dpfoservice.py CFG_HOME=/opt/apps/algo/algoS

bash-3.2$ /usr/ucb/ps -auxwee 6543
USER       PID %CPU %MEM   SZ  RSS TT       S    START  TIME COMMAND
alcrprun  6543  0.0  0.0 8752 5992 ?        S 19:35:01  0:15 /usr/bin/python -Bu ./bin/dpfoservice.py CFG_HOME=/opt/apps/algo/algoSuite.current.solaris.alcr/cfg RISK_HOME=/opt/apps/algo/algoSuite.current.solaris.alcr/risk++ ALGO_HOME=/opt/apps/algo/algoSuite.current.solaris.alcr ARE_HOME=/opt/apps/algo/algoSuite.current.solaris.alcr/aggregation/are 
...
...

Solution

  • It prints a 132-wide output to a file because that's what the -w argument does. Per the ps.1b man page:

    -w

    Uses a wide output format (132 columns rather than 80); if repeated, that is, -ww, use arbitrarily wide output. This information is used to decide how much of long commands to print.

    If you want arbitrary-width output, use -ww instead of -w.

    When using just the -w option and the output is a terminal window, /usr/ucb/ps appears to detect the terminal width on my copy of Solaris 11 - changing the width of the window modifies the amount of output emitted with just the -w option. The documentation for that behavior is likely buried somewhere on a Solaris man page, give the historical nature of Solaris documentation.