Alien-wxWidgets
view release on metacpan or search on metacpan
inc/inc_IPC-Cmd/IPC/Cmd.pm view on Meta::CPAN
=over 4
=item success
A simple boolean indicating if the command executed without errors or
not.
=item errorcode
If the first element of the return value (success) was 0, then some
error occurred. This second element is the error code the command
you requested exited with, if available.
=item full_buffer
This is an arrayreference containing all the output the command
generated.
Note that buffers are only available if you have C<IPC::Run> installed,
or if your system is able to work with C<IPC::Open3> -- See below).
This element will be C<undef> if this is not the case.
=item out_buffer
This is an arrayreference containing all the output sent to STDOUT the
command generated.
Note that buffers are only available if you have C<IPC::Run> installed,
or if your system is able to work with C<IPC::Open3> -- See below).
This element will be C<undef> if this is not the case.
=item error_buffer
This is an arrayreference containing all the output sent to STDERR the
command generated.
Note that buffers are only available if you have C<IPC::Run> installed,
or if your system is able to work with C<IPC::Open3> -- See below).
This element will be C<undef> if this is not the case.
=back
See the C<HOW IT WORKS> Section below to see how C<IPC::Cmd> decides
what modules or function calls to use when issuing a command.
=cut
sub run {
my %hash = @_;
### if the user didn't provide a buffer, we'll store it here.
my $def_buf = '';
my($verbose,$cmd,$buffer);
my $tmpl = {
verbose => { default => $VERBOSE, store => \$verbose },
buffer => { default => \$def_buf, store => \$buffer },
command => { required => 1, store => \$cmd,
allow => sub { !ref($_[0]) or ref($_[0]) eq 'ARRAY' }
},
};
unless( check( $tmpl, \%hash, $VERBOSE ) ) {
Carp::carp(loc("Could not validate input: %1", Params::Check->last_error));
return;
};
print loc("Running [%1]...\n", (ref $cmd ? "@$cmd" : $cmd)) if $verbose;
### did the user pass us a buffer to fill or not? if so, set this
### flag so we know what is expected of us
### XXX this is now being ignored. in the future, we could add diagnostic
### messages based on this logic
#my $user_provided_buffer = $buffer == \$def_buf ? 0 : 1;
### buffers that are to be captured
my( @buffer, @buff_err, @buff_out );
### capture STDOUT
my $_out_handler = sub {
my $buf = shift;
return unless defined $buf;
print STDOUT $buf if $verbose;
push @buffer, $buf;
push @buff_out, $buf;
};
### capture STDERR
my $_err_handler = sub {
my $buf = shift;
return unless defined $buf;
print STDERR $buf if $verbose;
push @buffer, $buf;
push @buff_err, $buf;
};
### flag to indicate we have a buffer captured
my $have_buffer = __PACKAGE__->can_capture_buffer ? 1 : 0;
### flag indicating if the subcall went ok
my $ok;
### IPC::Run is first choice if $USE_IPC_RUN is set.
if( $USE_IPC_RUN and __PACKAGE__->can_use_ipc_run( 1 ) ) {
### ipc::run handlers needs the command as a string or an array ref
__PACKAGE__->_debug( "# Using IPC::Run. Have buffer: $have_buffer" )
if $DEBUG;
$ok = __PACKAGE__->_ipc_run( $cmd, $_out_handler, $_err_handler );
### since IPC::Open3 works on all platforms, and just fails on
### win32 for capturing buffers, do that ideally
} elsif ( $USE_IPC_OPEN3 and __PACKAGE__->can_use_ipc_open3( 1 ) ) {
__PACKAGE__->_debug( "# Using IPC::Open3. Have buffer: $have_buffer" )
if $DEBUG;
### in case there are pipes in there;
### IPC::Open3 will call exec and exec will do the right thing
$ok = __PACKAGE__->_open3_run(
( run in 0.564 second using v1.01-cache-2.11-cpan-140bd7fdf52 )