in reply to Capturing STDERR (this is not a FAQ)

Preview != create :(

Capture::Tiny is indeed the way to go, with a small gotcha:

$ cat test.pl use 5.18.2; use warnings; use Capture::Tiny "capture"; my ($out, $err, $ext) = capture { # Local scope print STDERR "Output to STDERR\n"; warn "Warn!\n"; system "ls /tmp/bjfgerfbv"; qx{ls /tmp/jhgbejgrbe}; }; # Previous scope print STDERR "Hello world\n"; system "ls /tmp/foobar2"; print STDERR "OUT: $_\n" for split m/\n/ => $out; print STDERR "ERR: $_\n" for split m/\n/ => $err; $ perl test.pl Hello world /bin/ls: cannot access /tmp/foobar2: No such file or directory ERR: Output to STDERR ERR: Warn! ERR: /bin/ls: cannot access /tmp/bjfgerfbv: No such file or directory ERR: /bin/ls: cannot access /tmp/jhgbejgrbe: No such file or directory

The gotcha is that STDERR inside capture is not unbuffered, so if your last print STDERR "foo"; does not have a trailing newline, it is lost. That might change in a newer release (at least I hope)


Enjoy, Have FUN! H.Merijn