Gopakumar Ambat <[EMAIL PROTECTED]> writes: >Thanks Nick. You are right, the code appeared to be working more by chance! >Btw, I am using the #define WIN32IO_IS_STDIO. Without this if I execute the >same code (closing stderr, redirecting it to a file) in a loop, it hangs in >PerlIO_stderr()... I tried figuring out what this #define actually does, but >couldn't get much out of it.. Could you tell me what this would actually do?
I suspect is one of mine, but I don't remember what it does exactly. I was about 80% done on a "native" Win32 layer (which is still there) when the NTFS partition on that machine became useless. One day I may get back to it... I _think_ this option disables that buggy scheme in favour of one more like other systems. Will take a look. >I believe there wouldn't be any such issues with HPUX/Linux, but I would >need to do something like this for NetWare also... I have never used NetWare, but from mail on p5p it seems to be a similar port to the Win32 one. > >-----Original Message----- >From: Nick Ing-Simmons [mailto:[EMAIL PROTECTED] >Sent: Thursday, August 05, 2004 10:03 PM >To: [EMAIL PROTECTED] >Cc: [EMAIL PROTECTED]; 'Nick Ing-Simmons' >Subject: RE: How to redirect STDERR under WIN32 > >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);