I can't set stderr = fopen(..) since stderr cannot be an "l" value (it's
#defined in the C lib stdio).. What I can do is freopen(myfile,.., stderr),
which theoretically redirects stderr to the file "myfile". This works fine
on a simple C++ app, but not when perl.h is included... I guess perl.h
over-rides the default behavior of stderr and I am unable to figure out what
needs to be changed to over-ride Perl's interpretation!!!

I had purposefully removed the semicolon so that the perl interpreter fails
while parsing and returns an error!! :)

Thanks,
Gopa

-----Original Message-----
From: muppet [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, July 27, 2004 5:43 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: How to redirect STDERR under WIN32


On Jul 27, 2004, at 6:09 AM, Gopakumar Ambat wrote:

> ##########perl script:
> ##########test.pl
> use my_test.pm

that should be either "use my_test;" or "require 'my_test.pm';".  
either way, it needs a semicolon, or you get the syntax error you saw.  
you also are responsible for making sure this file is available through the
perl library search path.

> print "inside test.pl script";

don't forget that this probably won't show up until you print a newline to
stdout.


> My aim is to get the same error message while running the perl script 
> via the embedded C++ application. My understanding is that the error 
> message gets re-directed to "stderr", so I tried closing stderr and 
> reopening with a new file handle, but that doesn't seem to work; no 
> messages get routed to the "new" stderr!! Apparently the "stderr" has 
> been over-riden by the PERL IO layer, and I can't find a way to reset 
> that...

did you do

   fclose (stderr);
   stderr = fopen (...);

or

   close (2);
   dup (otherfd);

?

what i see is that PerlIO_stderr() calls PerlIO_stdstreams(), which, if 
it hasn't been called before, does PerlIO_fdopen(2, ...).  so, in 
theory, if you redirect stderr's file descriptor before perl sees it, 
it ought to work.

but, thanks to #ifdef magic, i don't know for sure that this code even 
gets called on win32, so you will want to take my comments with 
caution.  does win32 even have dup()?


--
Holy crap, dude, we have kids!
        -- Elysse, six days after giving birth to twins

Reply via email to