Hi Alex, Is the enum_files() function under your control? If so, you can make it print to the currently-selected Perl filehandle (which may be STDOUT) rather than directly to C's stdout descriptor. Then your select($iostr) will have the effect you want.
It looks like the currently-selected handle is stored in PL_defoutgv, but I'm not sure if that's "official API" or not. -Ken > -----Original Message----- > From: Alexandru Palade [mailto:[EMAIL PROTECTED] > Sent: Friday, July 08, 2005 9:37 AM > To: inline@perl.org > Subject: accesing the C-space stdout > > Hello everyone, > > I've got a little problem with an I/O redirection I'm trying > to do. I am writing a CGI script that uses a module I've made > using Inline C. > The redirection looks something like this: > > $iostr = IO::String->new($listing); > $old_iostr = select($iostr); > > #get the listing and reset stdout > $chm->enum_files("", 1); > select($old_iostr) > if defined($old_iostr); > > The basic idea is that $chm->enum_files(...) outputs > something to stdout and I want to capture that and put it > into $listing. > Unfortunately, $chm->enum_files(...) is actually a C > function, and when that C function writes to stdout, it gets > on the screen regardless of my redirection. I did a test and > saw that if I replace the $chm->enum_files(...) call with a > print statement, the redirection works (so it works fine from > Perl-space). > > I've read somewhere that the problem is that Perl has it's > own stdout which is different than the C-space stdout, so if > I want my redirection to work I have to somehow make the Perl > stdout point to the C-space stdout structure before > redirecting it. However I have no idea how to do this and > I've searched the Internet for a couple of hours already. > > ...help... > > > Alex >