In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Perl.Org) writes:
>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?

What makes you think that the output of the subprocess isn't going to be
captured just because the parent's output is redirected?  The subprocess's
handles are created anew, not duped.  A test shows it:

sh-2.05a$ cat bar
cat: bar: No such file or directory
sh-2.05a$ perl -le 'print "STDOUT"; $x=`ls foo bar 2>&1`; warn "STDERR"; print $x' 
>foo 2>baz
sh-2.05a$ cat foo
STDOUT
ls: bar: No such file or directory
foo

sh-2.05a$ cat baz
STDERR at -e line 1.
sh-2.05a$ 

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/

-- 
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