Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^4: STDERR going to string

by philkime (Sexton)
on Oct 11, 2011 at 08:21 UTC ( #930761=note: print w/replies, xml ) Need Help??

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

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.

Replies are listed 'Best First'.
Re^5: STDERR going to string
by Anonymous Monk on Oct 11, 2011 at 09:06 UTC

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

    Like I already said, launch a process

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

      I don't think I understand how to do that in my case. I am in the middle of a large program and need to make some sub calls to some XS/external lib subs. There isn't anything I can really launch as an external processs here. Am I missing something? I know it'll always work if I redirect everything before I start but my problem is that I am already deep in some code at the point where I need to run some XS subs and get their STDERR.

        Am I missing something?

        $ perl -le " print for map { fileno $_ } \*STDIN, \*STDOUT, \*STDERR +" 0 1 2

        There is nothing you can do to change the fileno of STDIN/STDOUT/STDERR on a c-level on win32, they're always 0 1 2, so any c code printing on STDERR is printing on 2, always

        To capture STDERR you have to launch a process, or

        Patch XS module to use perl functions for printing to stderr (perlclib), so that when you redirect STDERR/STDOUT (like using IO::NestedCapture), it notices

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930761]
[holli]: what? the pm code you swindled your way into?
[LanX]: no already the pm code I'm allowed to see ... http://www. 1203338;style=css
[LanX]: understanding this code is like relearning space invaders and donkey Kong at the same time
[holli]: i saw that thread and figured it`s OPP value too high. i didnt realise its PM code

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2017-11-20 21:34 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (294 votes). Check out past polls.