Perl calling ps - COLUMNS ignored?


N

neilsolent

Hi

I am seeing weird behaviour when calling ps from perl on AIX.
I want to control the width of the output from ps through the COLUMNS environment variable.
The shell script gives truncated output when run directly, but
seems to ignore COLUMNS when called from Perl! Can anyone explain why?

thanks,
Neil.

[email protected]:/tmp# cat /tmp/a.sh
#!/bin/sh
COLUMNS=10
export COLUMNS
ps -fu prdgwd -o "%u;%p;%P;%C;%y;%x;%a"

[email protected]:/tmp# cat /tmp/a.pl
#!/bin/perl
print `/tmp/a.sh`;

[email protected]:/tmp# /tmp/a.sh
RUSER PID PPID %CPU TT TIME COMMAND
prdgwd; 3604630;12910802; 0.0; pts/2; 00:00:00;-ksh
prdgwd;10223670; 3211486; 0.0; -; 00:00:00;/bin/ksh /usr/l
prdgwd;10551322;10223670; 0.0; -; 00:00:00;sleep 900
prdgwd;11075748; 1; 0.0; -; 00:00:27;/opt/IBM/ITM/ha
prdgwd;13566176;19529852; 0.0; -; 00:00:00;db2vend (PD Ven
prdgwd;18153590;19529852; 0.0; -; 00:00:06;db2acd
prdgwd;19005538;19529852; 0.2; -; 00:03:45;db2sysc 0
prdgwd;20971672; 3604630; 0.0; pts/2; 00:00:16;db2top -d clsgw

[email protected]:/tmp# /tmp/a.pl
RUSER PID PPID %CPU TT TIME COMMAND
prdgwd; 3604630;12910802; 0.0; pts/2; 00:00:00;-ksh
prdgwd;10223670; 3211486; 0.0; -; 00:00:00;/bin/ksh /usr/local/dbabin/db2_log_cleanup.ksh
prdgwd;10551322;10223670; 0.0; -; 00:00:00;sleep 900
prdgwd;11075748; 1; 0.0; -; 00:00:27;/opt/IBM/ITM/ha/aix526/ud/bin/kuddb2 clsppal38_prdgwd
prdgwd;13566176;19529852; 0.0; -; 00:00:00;db2vend (PD Vendor Process - 258)
prdgwd;18153590;19529852; 0.0; -; 00:00:06;db2acd
prdgwd;19005538;19529852; 0.2; -; 00:03:45;db2sysc 0
prdgwd;20971672; 3604630; 0.0; pts/2; 00:00:16;db2top -d clsgwd
 
Ad

Advertisements

N

neilsolent

Probably because your ps only honours COLUMNS when output is to a

terminal. If you just want to cut the output off at a given column,

that's not hard; something like



my @ps = `ps ...`;

length > 49 and substr($_, 49) = ""

for @ps;



Ben


Thanks Ben. You are right of course - I think ps is testing stdout for being a terminal. So this has nothing to do with perl.
I posted this to troubleshoot a wider problem - although you have answered the post I still have not solved the problem - oh well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top