Gopakumar Ambat <[EMAIL PROTECTED]> writes:
>Thanks for your response.
>I have got around the problem doing this (checked on Win32):
>
>  //first close the stderr opened by PERL
>  //open it again, and dup it...
>  int code = PerlIO_close(PerlIO_stderr());
>if(code == 0)
>{
>  PerlIO* newprlIO = PerlIO_open("prl.txt", "a+");

Ok.

>
>  PerlLIO_dup2(fileno((FILE*) (newprlIO)),fileno((FILE*)PerlIO_stderr()));  

That line is almost completely wrong ;-)
newprlIO is NOT a FILE * and using the fileno() function on it as it it was
is going to give you rubbish. 

Also PerlIO_stderr() has been closed above, so it doesn't have a fileno.

Your code works because although that line fails, the PerlIO_open()
will have used lowest numbered free fd (i.e. number 2 freed up 
by closing stderr) for the newprlIO.

You could correct that line to read:

    PerlLIO_dup2(PerlIO_fileno(newprlIO),2)

If you don't like the hard-coded 2 
then you could do it like so:

int stderr_fd = PerlIO_fileno(PerlIO_stderr());
PerlIO_close(PerlIO_stderr());
...
    PerlLIO_dup2(PerlIO_fileno(newprlIO),stderr_fd);


Reply via email to