Example 7-10. examples/io/capture.pl
#!/usr/bin/perl -w
use strict;
use Test::More tests => 2;
my $app = "./examples/io/application.pl";
my @in = ('10', '21', 'hello', '3x');
my $in = join "\n", @in;
my @expected_out = ('20', '42');
my @expected_err = (
"The input 'hello' contains no numeric values",
"The input '3x' contains no numeric values",
);
{
open my $fh, ">", "/tmp/in" or die $!;
print $fh $in;
}
system "$app < /tmp/in > /tmp/out 2> /tmp/err";
{
open my $fh, "<", "/tmp/out" or die $!;
my @out = <$fh>;
chomp @out;
is_deeply(\@out, \@expected_out, "Output");
}
{
open my $fh, "<", "/tmp/err" or die $!;
my @err = <$fh>;
chomp @err;
is_deeply(\@err, \@expected_err, "Error");
}
| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| Capturing both STDOUT and STDERR | Up | Capturing both STDOUT and STDERR using IPC::Run3 |