perl.org wrote:
Hi,

Is there a way to explicitly open a handle to the "console", or wherever STDOUT/STDERR are directed to by default?

My process is running in an environment in which STDOUT and STDERR have already been redirected. I want to intercept these streams when running command line tools, then restore them afterwards. I want to be able to call my command line tool like:

my ${ret} = `command 2>&1`;

and have ${ret} get the both STDOUT and STDERR. This piece gets called a lot so I want to avoid temp files if I can. This has to work on Windows if that makes any difference (I think that means no /dev/console, etc.). I know about:

open( RESTORESTDOUT, '>>&STDOUT' );

and I think I can restore the redirected STDOUT from there, but how to I open STDOUT so that it goes to the "console", as if it had never been redirected?

Hopefully this makes some sense.

open( OUT, 'con' ); # IIRC

I /think/ you can also use POSIX::fdopen() or IO::Handle::new_from_fd() to get the standard streams.

Randy.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to