in reply to top and STDERR hell...

FWIW, I get good results with backticks. For example:

% perl -MList::Util=max -lwe ' print max map length, `COLUMNS=1000 top -bcS -n 1 2>err.txt`' 208
The output is 81 if I omit the "COLUMNS=1000" bit.

My system is Debian Linux, and

% top --version top (procps version 2.0.7)

the lowliest monk

Replies are listed 'Best First'.
Re^2: top and STDERR hell...
by DouglasDD (Beadle) on Jun 08, 2005 at 02:07 UTC
    Damn, backticks didn't occur to me. (somehow I've gotten in the habit of always using open(H, "app |")). I'll try this out as soon as I get back in the office tomorrow - will let you know.

    Thanks!
    ./ddd

      Actually, it's not a backtick thing; that was just the first thing I tried; when I run your code I also get the desired results. Specifically:

      # lll.pl sub longestLineLength { my $longestLen = undef; for my $l ( @_ ) { if ( length($l) > $longestLen ) { $longestLen = length($l); } } return $longestLen; } 1; # propitiatory offering for require __END__ # test03.pl use strict; use warnings; require "lll.pl"; open (TOP, "COLUMNS=1000 /usr/bin/top -bcS -n 1 2>err.txt|") || die "open pipe from top failed $!"; print longestLineLength( <TOP> ) . "\n"; __END__ % perl test03.pl 208

      the lowliest monk

        Hmm, double-checked these and still get the same failing results. I can't explain the disparity between similar-sounding linux (procps) systems.

        Thanks for the data point.
        ./ddd

      Nope. Same behavior with backticks.
      Darn.