Perl calling ps - COLUMNS ignored?

Discussion in 'Perl Misc' started by neilsolent, Jul 10, 2013.

  1. neilsolent

    neilsolent Guest

    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.

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

    root@test1:/tmp# cat /tmp/a.pl
    #!/bin/perl
    print `/tmp/a.sh`;

    root@test1:/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

    root@test1:/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
     
    neilsolent, Jul 10, 2013
    #1
    1. Advertising

  2. neilsolent

    neilsolent Guest

    On Wednesday, 10 July 2013 18:10:25 UTC+1, Ben Morrow wrote:
    > Quoth neilsolent <>:
    >
    > >

    >
    > > 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?

    >
    >
    >
    > 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.
     
    neilsolent, Jul 11, 2013
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. helpful sql
    Replies:
    0
    Views:
    815
    helpful sql
    May 19, 2005
  2. Replies:
    5
    Views:
    598
  3. Replies:
    4
    Views:
    940
  4. Mike Bridge

    WebProxy ignored calling WebMethod

    Mike Bridge, May 1, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    179
    Mike Bridge
    May 1, 2006
  5. Thomas Glanzmann
    Replies:
    0
    Views:
    171
    Thomas Glanzmann
    Jan 8, 2004
Loading...

Share This Page