On Aug 28, 12:45 am, ole...@gmail.com (marcos rebelo) wrote: > I'm having a more or less complicated code, that was simplified to this. > > use strict; > use warnings; > use IPC::Open3; > use IO::Handle; > use Test::More; > use Test::Trap; > > sub shell_run { > my ($stdin, $stdout, $stderr) = map {IO::Handle->new} (0..2); > > print "YYYY"; > > open3($stdin, $stdout, $stderr, @_); > > foreach my $line (<$stdout>, <$stderr>) { > print "read: $line"; > } > > print "ZZZZ"; > > } > > trap {shell_run('perl', '-E', 'print "TEXT IN"')}; > > #is( $trap->stdout, "YYYYZZZZ"); > is( $trap->stdout, "YYYYTEXT INZZZZ"); > > done_testing(); > > I would expect to have the test 'is( $trap->stdout, "YYYYTEXT > INZZZZ");' executing ok, instead of that I have the test 'is( > $trap->stdout, "YYYYZZZZ");'. > > I need to test the output inside the loop in there, I have tried allot > of solution but I just don't get it
Since you mention simplifying the code, do you actually need IPC::Open3 ? In your sample code, you're only reading process output. If you don't need IPC::Open3 complexity, you could just use magic open to read output : sub shell_run { print "YYYY"; my $pid = open( my $fh, qq{ @_ | } ) or die "open: $!"; print for <$fh>; close $fh or die "close: ", $? || $!; print "ZZZZ"; } trap { shell_run( 'perl', '-E', '"print \'TEXT IN\'"' ) }; is( $trap->stdout, "YYYYTEXT INZZZZ"); done_testing(); --> ok 1 1..1 -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/