# Generated by Pod::WikiDoc version 0.18

=pod


=head1 NAME

IO::CaptureOutput - capture STDOUT and STDERR from Perl code, subprocesses or XS

=head1 VERSION

This documentation describes version 1.04_01.

=head1 SYNOPSIS

     use IO::CaptureOutput qw(capture capture_exec qxx);
 
     my ($stdout, $stderr);
     capture sub {noisy(@args)}, \$stdout, \$stderr;
     sub noisy {
         my @args = @_;
         warn "this sub prints to stdout and stderr!";
         ...
         print "finished";
     }
 
     ($stdout, $stderr) = capture_exec( 'perl', '-e', 
         'print "Hello "; print STDERR "World!"');

=head1 DESCRIPTION

This module provides routines for capturing STDOUT and STDERR from forked
system calls (e.g. C<<< system() >>>, C<<< fork() >>>) and from XSE<sol>C modules.

=head1 FUNCTIONS

The following functions are be exported on demand.

=head2 C<<< capture(\&subroutine, \$output, \$error) >>>

Captures everything printed to C<<< STDOUT >>> and C<<< STDERR >>> for the duration of
C<<< &subroutine >>>. C<<< $output >>> and C<<< $error >>> are optional scalar references that
will contain C<<< STDOUT >>> and C<<< STDERR >>> respectively.

Returns the return value(s) of C<<< &subroutine >>>. The sub is called in the same
context as C<<< capture() >>> was called e.g.:

     @rv = capture(sub {wantarray}); # returns true
     $rv = capture(sub {wantarray}); # returns defined, but not true
     capture(sub {wantarray});       # void, returns undef

C<<< capture() >>> is able to trap output from subprocesses and C code, which
traditional C<<< tie() >>> methods are unable to capture.

B<Note:> C<<< capture() >>> will only capture output that has been written or flushed
to the filehandle.

=head2 C<<< capture_exec(@args) >>>

Captures and returns the output from C<<< system(@args) >>>. In scalar context,
C<<< capture_exec() >>> will return what was printed to C<<< STDOUT >>>. In list context,
it returns what was printed to C<<< STDOUT >>> and C<<< STDERR >>>

     my $output = capture_exec('perl', '-e', 'print "hello world"');
 
     my ($output, $error) = capture_exec('perl', '-e', 'warn "Test"');

C<<< capture_exec >>> passes its arguments to C<<< CORE::system >>> it can take advantage
of the shell quoting, which makes it a handy and slightly more portable
alternative to backticks, piped C<<< open() >>> and C<<< IPC::Open3 >>>.

You can check the exit status of the C<<< system() >>> call with the C<<< $? >>>
variable. See L<perlvar> for more information.

=head2 C<<< qxx(@args) >>>

This is an alias of C<<< capture_exec >>>

=head1 SEE ALSO

=over

=item *

L<IPC::Open3>

=item *

L<IO::Capture>

=item *

L<IO::Utils>

=back

=head1 AUTHORS

=over

=item *

Simon Flack E<lt>simonflk _AT_ cpan.orgE<gt> (original author)

=item *

David Golden E<lt>dagolden _AT_ cpan.orgE<gt> (co-maintainer since version 1.04)

=back

=head1 COPYRIGHT AND LICENSE

Portions copyright 2004, 2005 Simon Flack.  Portions copyright 2007 David
Golden.  All rights reserved.

You may distribute under the terms of either the GNU General Public License or
the Artistic License, as specified in the Perl README file.


