in reply to Re: perl function for 'ps' ?
in thread perl function for 'ps' ?

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

Replies are listed 'Best First'.
Re^3: perl function for 'ps' ?
by nimdokk (Vicar) on Aug 14, 2006 at 14:29 UTC
    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.
Re^3: perl function for 'ps' ?
by gellyfish (Monsignor) on Aug 14, 2006 at 14:26 UTC

    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.