Capture::Tiny — search.cpan.org

Capture::Tiny provides a simple, portable way to capture almost anything sent to STDOUT or STDERR, regardless of whether it comes from Perl, from XS code or from an external program. Optionally, output can be teed so that it is captured while being passed through to the original filehandles. Yes, it even works on Windows (usually). Stop guessing which of a dozen capturing modules to use in any particular situation and just use this one.

Источник: Capture::Tiny — search.cpan.org.

   use Capture::Tiny ':all';
 
   # capture from external command
 
   ($stdout, $stderr, $exit) = capture {
     system( $cmd, @args );
   };
 
   # capture from arbitrary code (Perl or external)
 
   ($stdout, $stderr, @result) = capture {
     # your code here
   };
 
   # capture partial or merged output
 
   $stdout = capture_stdout { ... };
   $stderr = capture_stderr { ... };
   $merged = capture_merged { ... };
 
   # tee output
 
   ($stdout, $stderr) = tee {
     # your code here
   };
 
   $stdout = tee_stdout { ... };
   $stderr = tee_stderr { ... };
   $merged = tee_merged { ... };

Leave a Reply