On Aug 29, 10:46 pm, ole...@gmail.com (marcos rebelo) wrote:
> We are out of contest in here.
>
> I know how to run open3, but I don't know how to test it. Repeating
>

Hm,  I just wanted to warn you that Open3 may
easily require more paranoia than you've shown...
your sample is simple enough to escape problems
but deadlock often lurks, especially if lots of data is
sent down the pipe. IO::Select can help with this.

Meanwhile,  I made a few tweaks to your program
which now works for me (at least on FreeBSD).

* Take a look at the Test::Trap reviews on CPAN,
   for useful info on the the 'use Test::Trap ...' import
   list,  especially Shlomi's.

--
Charles DeRykus

use strict;
use warnings;

use IPC::Open3;
use IO::Handle;
use Test::More;
use Test::Trap qw(
   trap $trap
   :flow
   :stderr(systemsafe)
   :stdout(systemsafe)
   :warn
);

$| = 1;

sub shell_run {
    my ($stdin, $stdout, $stderr) = map {IO::Handle->new} (0..2);

    print  "YYYY";

    open3($stdin, $stdout, $stderr, @_);

    close( $stdin ) or die "close: $! $@";

    foreach my $line ( ( defined $stderr ? <$stderr> : () ),
                               ( defined $stdout ? <$stdout> : () )  )
    {
            print $line;
    }

    print  "ZZZZ";

    close ( $stderr ) if defined $stderr;
    close ( $stdout ) if defined $stdout;

}

trap {shell_run('perl', '-e', 'print "TEXT IN"')};

is( $trap->stdout, "YYYYTEXT INZZZZ");

done_testing();
__END__

-----> ok 1
         1..1


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to