in reply to Re: Re: capturing STDERR within a script
in thread capturing STDERR within a script

Instead of


as the last line of the sub, try


It has to do with the return value of the sub, which is $_ in this case, and need to be an empty list if you want no output. The return value of the sub needs to be a list suitable for processing by the original file handle. In this case silence is an empty list.

If all you want to do is capture the output, not process it, use the code from the Filter::Handle module

Filter \*STDERR, sub {push @DATA, "@_"; ()};

noisy stuff occurs...

UnFilter \*STDERR;

@DATA now holds all the noise emitted on STDERR.