demerphq wrote:
On 9/18/06, Ovid <[EMAIL PROTECTED]> wrote:
I've gotten a report that the open command fails on Windows. Not a surprise, now that I think about it. However, I don't know of any portable way of forcing STDERR to STDOUT (and I don't have a Windows box handy). This means that my 2000+ TAPx::Parser tests are in trouble. If Test::Builder accepted an environment variable which allowed me to override this, I might have a way out. So far removing the 2>&1 seems to make my tests pass on a Linux box, but that strikes me as bizarre as I thought STDERR wouldn't get read that way. What the heck am I misunderstanding?

The easiest way I know of to execute a process in win32 and get both
the stderr and stdout back is to use backticks.

my $res=`$cmd 2>&1`;

I found that the suggested code for saving and restoring STDOUT and STDERR given in "perldoc -f open" seems to work OK. This is essentially what IPC::Run3 is doing -- capturing to an external file and then reading it back in and making it available.

I use it in CPAN::Reporter -- see t\03_test_report.t:

local *OLDOUT;
    open( OLDOUT, ">&STDOUT" )
        or die "Couldn't save STDOUT before testing";

    open( STDOUT, ">$temp_stdout" )
        or die "Couldn't redirect STDOUT before testing";
    $|++;

    my $makefile_rc = ! system("$perl Makefile.PL");
    my $test_make_rc = CPAN::Reporter::test( $dist, "$make test" );
    system("$make realclean");
close(STDOUT); open(STDOUT, ">&OLDOUT");

Tests pass on Linux, Darwin, Win32, Netbsd and Freebsd accorting to CPAN::Testers. While that's only STDOUT, the recipe in perldoc seems to imply you could reopen STDERR to a duplicate of STDOUT (after redirecting it) to capture both to the same place.

As a side note, it would be nice if IO::Capture or Test::Output used that method instead of ties so they could be used with external processes, too.

In the meantime, I'd suggest trying it with IPC::Run3, which should do the right thing.

Regards,
David Golden

Reply via email to