develooper Front page | perl.perl5.porters | Postings from October 2011

Problem with redirecting STDERR from libraries called by XS under windows

From:
Philip Kime
Date:
October 13, 2011 07:46
Subject:
Problem with redirecting STDERR from libraries called by XS under windows
Message ID:
E883D485-7E72-465B-A43B-5CCB6611AF41@kime.org.uk
After much gnashing of teeth on perlmonks, I think I need a real expert pronouncement on this issue. I am using an XS module (Text::BibTeX) which calls an external library (libbtparse). On windows, I can find no way to capture the STDERR from the libbtparse library which uses generic fprintf(stderr … calls. I've tried everything, including Capture::Tiny. It seems to be a windows thing which I'm hoping someone can explain. I have all but lost hope of getting it work, short of re-writing the library to use perlIO. Here is a minimal example which display the issue. It uses Inline::C and clearly shows that it seems impossible to capture STDERR on windows in such cases. On non-Windows (cygwin included), it outputs correctly:

|ERROR|

On Windows, it gives:

||
ERROR

which shows you that the STDERR isn't being captured.

PK

-----------------------------------------------------------------------

use File::Temp qw(tempfile);
use Inline C;

open my $olderr, '>&STDERR'; # save STDERR
my ($fh, $fn) = tempfile();
open STDERR, '>&', $fh;

test_err();

open STDERR, '>&', $olderr; # reset STDERR
close $fh;

open my $e, '<', $fn;
my $err = <$e>;
print "|$err|\n";

__END__
__C__
void test_err()
{
(void)fprintf (stderr, "ERROR");
}
--
Dr Philip Kime




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About