The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

IO::AsyncX::System - fork+exec, capturing STDOUT/STDERR

VERSION

version 0.003

SYNOPSIS

 use feature qw(say);
 use IO::Async::Loop;
 use IO::AsyncX::System;
 my $loop = IO::Async::Loop->new;
 $loop->add(
  my $system = IO::AsyncX::System->new
 );
 my ($code, $stdout, $stderr) = $system->run([qw(ls)])->get;
 say for @$stdout;

DESCRIPTION

Intended as a replacement for "system" in IO::Async-using code. Provides a single "run" method which will fork+exec (via IO::Async::Process), capturing STDOUT/STDERR, and returning a Future holding the exit code and output.

METHODS

run

Takes a single parameter defining the command to run:

 $system->run(['ls']);

plus optional named parameters:

  • utf8 - interprets all input/output as UTF-8, so STDOUT/STDERR will be returned as arrayrefs containing Perl strings rather than raw bytes

  • binary - the reverse of utf8 (and the default)

  • stdin - an arrayref of data to pass as STDIN

  • timeout - kill the process if it doesn't complete within this many seconds

Returns a Future which resolves to the exit code, STDOUT and STDERR arrayrefs:

 $system->run([...]) ==> ($exitcode, $stdout_arrayref, $stderr_arrayref)

STDIN/STDOUT/STDERR are arrayrefs split by line. In binary mode, they will hold a single element each.

SEE ALSO

INHERITED METHODS

IO::Async::Notifier

add_child, adopt_future, can_event, children, configure, configure_unknown, debug_printf, get_loop, invoke_error, invoke_event, loop, make_event_cb, maybe_invoke_event, maybe_make_event_cb, new, notifier_name, parent, remove_child, remove_from_parent

AUTHOR

Tom Molesworth <cpan@perlsite.co.uk>

LICENSE

Copyright Tom Molesworth 2015. Licensed under the same terms as Perl itself.