in reply to perl function for 'ps' ?

on Solaris, it truncates the command arguments to the first 80 bytes

Well ... you could always just recognize you're on solaris and use /usr/ucb/ps -auxw instead of /bin/ps -ef

-derby

Replies are listed 'Best First'.
Re^2: perl function for 'ps' ?
by Moron (Curate) on Aug 14, 2006 at 14:06 UTC
    And could use 'uname' to check the OS, for example:
    my $os = `uname`; chop $os; my $cmd = ( $os eq 'SunOS' ) ? '/usr/ucb -auxw' : '/bin/ps -ef'; my @psout = split /\n/, `$cmd`; my @hdr = split /\s+/, shift ( @psout ); my @aoh = (); while (1) { # load ps output into above array of hash... my $fldno = 0; my $tmp = {}; my @fld = ( split /\s+/,( shift( @psout ) || last )); $tmp -> { $hdr [ $fldno++ ] } = shift @fld for @hdr; $tmp -> { COMMAND } .= join ' ', @fld; push @aoh, $tmp; }

    -M

    Free your mind

      And yet another Perl-ish way to check the OS is to look at $^O (or if you use English, you can check it as $OSNAME). For instance something like the following would work:

      use English; BEGIN { if ( $OSNAME =~ /MSWin32/i) { #do some stuff for Windows } elsif ( $OSNAME =~ /solaris/i) { #do some stuff for solaris }# }#end BEGIN
      You could put in whatever the various OSes are that you would need.

      I'm not sure there is any advantage in this case in using `uname` over $^O here, $^O does however contain "solaris" rather than "SunOS" on the Solaris machine I have to test with.

      /J\

      A reply falls below the community's threshold of quality. You may see it by logging in.