Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: STDERR going to string

by philkime (Sexton)
on Oct 10, 2011 at 13:23 UTC ( #930629=note: print w/ replies, xml ) Need Help??


in reply to Re: STDERR going to string
in thread STDERR going to string

I can get around this by redirecting to a file and reading it later. I suspect I could use Config::Tiny or File::Tee too but it seems it's a harder problem on Windows because re-opening STDERR decouples perl's STDERR from the called C library's STDERR which seems impossible to capture. If anyone has any ideas about this ... Since the issue is a library called from XS and not the XS extension itself and the fact that this library is also used apart from perl, it can't be modified to use PerlIO ...


Comment on Re^2: STDERR going to string
Re^3: STDERR going to string
by Anonymous Monk on Oct 10, 2011 at 13:38 UTC
      It's not really the output of an external command etc. I need. It's the STDERR of a C library which an XS module uses. So when I make certain sub calls, it gets into the C routines and it's their STDERR I want to capture. It all works fine on non-Windows using STDERR redirection to a file or Capture::Tiny but on Windows, the STDERR of the library refuses to be captured. This seems to be a windows specific thing - I read somewhere that re-opening STDERR on windows de-couples perl STDERR from the C library STDERR. If so, I'm really in the dark as to how to capture this.

        ...repetitive...I'm really in the dark as to how to capture this.

        Like I already said, launch a process

        perl foo.pl 1>my.stdout.txt 2>my.stderr.txt always works

Re^3: STDERR going to string
by Anonymous Monk on Oct 12, 2011 at 10:13 UTC

    because re-opening STDERR decouples perl's STDERR from the called C library's STDERR

    It will probably work if you save/dup STDERR and restore it

    open my $errsave, '>&', STDERR or do { print "couldn't dup STDERR: $!"; exit 2; }; open STDERR ... ... open STDERR, '>&', $errsave or do { print "couldn't restore/dup STDERR: $!"; exit 2; };

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930629]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-08-01 08:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (257 votes), past polls