AnyEvent-Proc

 view release on metacpan or  search on metacpan

lib/AnyEvent/Proc.pm  view on Meta::CPAN

=head2 writeln(@lines)

Queues one or more line to be written.

=head2 pipe([$fd, ]$peer)

Pipes any output of STDOUT to another handle. C<$peer> maybe another L<AnyEvent::Proc> instance, an L<AnyEvent::Handle>, a L<Coro::Channel>, an object that implements the I<print> method (like L<IO::Handle>, including any subclass), a ScalarRef or a ...

C<$fd> defaults to I<stdout>.

	$proc->pipe(stderr => $socket);

=head2 pull($peer)

Pulls any data from another handle to STDIN. C<$peer> maybe another L<AnyEvent::Proc> instance, an L<AnyEvent::Handle>, an L<IO::Handle> (including any subclass), a L<Coro::Channel>, a ScalarRef or a GlobRef.

	$proc->pull($socket);

=head2 readline_cb($callback)

Reads a single line from STDOUT and calls C<$callback>

t/005-to_scalar.t  view on Meta::CPAN

    $proc = AnyEvent::Proc->new(
        bin    => $bin,
        ttl    => 5,
        outstr => \$out,
        errstr => \$err
    );
    $proc->writeln($$);
    $proc->finish;
    is $proc->wait() => 0,           'wait ok, status is 0';
    like $out        => qr{^$$\s*$}, 'stdout is my pid';
    like $err        => qr{^\s*$},   'stderr is empty';

    $out = '';
    $err = '';

    $proc = AnyEvent::Proc->new(
        bin    => $bin,
        args   => [qw[ THISFILEDOESNOTEXISTSATALL ]],
        ttl    => 5,
        outstr => \$out,
        errstr => \$err
    );
    $proc->finish;
    isnt $proc->wait() => 0,         'wait ok, status isnt 0';
    like $out          => qr{^\s*$}, 'stdout is empty';
    like $err => qr{^.*no such file or directory\s*$}i,
      'stderr hat error message';
}

done_testing;

t/007-run.t  view on Meta::CPAN

    $out = run( $bin => $$ );
    like $out => qr{^$$\s*$}, 'stdout is my pid';
}

SKIP: {
    my ($bin) = Env::Path->PATH->Whence('cat');
    skip "test, reason: executable 'cat' not available", 2 unless $bin;
    ( $out, $err ) = run( $bin => 'THISFILEDOESNOTEXISTSATALL' );
    like $out => qr{^\s*$}, 'stdout is empty';
    like $err => qr{^.*no such file or directory\s*$}i,
      'stderr hat error message';
}

SKIP: {
    my ($bin) = Env::Path->PATH->Whence('false');
    skip "test, reason: executable 'false' not available", 1 unless $bin;
    run($bin);
    is $?>> 8 => 1,
      'exit code is properly saved in $?';
}



( run in 1.294 second using v1.01-cache-2.11-cpan-49f99fa48dc )