Subject: | Can't capture output from system() calls |
I'm trying to run tests on Perl one-liners. I wanted to use Test::Output
to capture the results. Unfortunately, it appears that it doesn't work
on system() calls.
The attached program shows that if you use output_from on prints to
STDOUT and STDERR, they work just fine. but if you use output_from on a
system("perl -e 'print ...'") it doesn't work. (I got the output file by
running perl test_output_bug.pl >& test_output_bug.out.)
The same thing happens on Windows and UNIX, btw.
Using the more primitive capture method in perldoc -f open() - simply
duping STDOUT and sending it and STDERR to files which you then read in
- works, but does require a temp file (as far as I know).
Anyway, T::O is great! keep up the good work.
-Amir Karger
Subject: | test_output_bug.pl |
#!/usr/local/bin/perl
use strict;
use warnings;
use Test::More qw(no_plan);
use Test::Output qw(stdout_from stderr_from combined_from output_from);
my ($x, $y);
($x, $y) = output_from(sub {print qq~stdout~; print STDERR qq~stderr~});
print "'$x'$y'\n";
($x, $y) = output_from(sub {system
'perl -e "print qq~stdout~; print STDERR qq~stderr~"'});
print "'$x'$y'\n";
($x, $y) = output_from(sub {system 'echo "hi" && ls JKFLDSF'});
print "'$x'$y'\n";
Subject: | test_output_bug.out |
Message body not shown because it is not plain text.