-----Original Message----- From: Dr.Ruud [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 10, 2006 11:08 AM To: dbi-users@perl.org Subject: Re: :XBase, STDOUT, and IO issue > > Garrett, Philip: > >> Mark Galbreath: > > >> I searched all night and cannot find an example of how to do this > >> correctly. Capture the table dump's STDOUT with IO::Pipe somehow? The > >> documentation of IO::Pipe is pretty sparse. Any suggestion is greatly > >> appreciated. > > > > This should do it: > > > > use IO::Handle; > > no warnings 'once'; # perl doesn't see the 2nd ref in the string > > > > # temporarily replace STDOUT > > open( SAVED_STDOUT, ">&STDOUT" ) or die "can't dup stdout: $!"; > > open( OUT_FILE, ">", "data.txt") or die "can't create file: $!"; > > STDOUT->fdopen(fileno(OUT_FILE), "w") || die "can't fdopen: $!"; > > > > # print data to temporary STDOUT > > $table->dump_records( "fs" => "|" ); > > > > # restore STDOUT > > open( STDOUT, ">&SAVED_STDOUT" ) or die "can't dup saved: $!"; > > > > # close/flush data file > > close(OUT_FILE) || die "can't close: $!"; > > Doesn't select() do what you need? perldoc -f select
Yeah, you're right. I don't know XBase, so I just assumed it was explicitly printing to STDOUT (which select() wouldn't help with). I just now looked at the XBase code and it does use the default filehandle. So, Mark, this will do it too: select(OUT_FILE); $table->dump_records(...); select(STDOUT);