RE: :XBase, STDOUT, and IO issue
am 10.05.2006 17:17:44 von Philip.Garrett-----Original Message-----
From: Dr.Ruud [mailto:rvtol+news@isolution.nl]=20
Sent: Wednesday, May 10, 2006 11:08 AM
To: dbi-users@perl.org
Subject: Re: :XBase, STDOUT, and IO issue
>=20
> Garrett, Philip:
> >> Mark Galbreath:
>=20
> >> I searched all night and cannot find an example of how to do this=20
> >> correctly. Capture the table dump's STDOUT with IO::Pipe somehow?
The=20
> >> documentation of IO::Pipe is pretty sparse. Any suggestion is
greatly=20
> >> 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" =3D> "|" );
> >
> > # restore STDOUT
> > open( STDOUT, ">&SAVED_STDOUT" ) or die "can't dup saved: $!";
> >
> > # close/flush data file
> > close(OUT_FILE) || die "can't close: $!";
>=20
> 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);