(dan baker) writes:
> wrote in message news:<. com>...
>> No I'm not a stuttering typist. ;^)
>>
>> I'm in the pecular position of working in an environment in which
>> STDOUT has been rudely redirected by a script (A) that runs my
>> scripts (B). I want to take STDOUT back without knowing the
>> handle to which it was redirected. I've found a lot of advise
>> on redirecting STDOUT, but I need to re-redirect it back to the
>> console from 'B' without hacking 'A'.
>> -------------------
On my Solaris system at least, the original STDOUT filehandle is lost
when a new one is opened. The original filehandle is on file
descriptor 1, and when STDOUT is opened to a new place, that file
descriptor is replaced:
$ truss perl -e'open(STDOUT,"> /tmp/test")'
...
open64("/tmp/test", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
fstat64(3, 0x00124D40) = 0
fcntl(3, F_DUP2FD, 0x00000001) = 1
close(3) = 0
...
(use strace instaed of truss on a Linux system)
That fcntl is a dup2 operation, which closes filehandle 1, then makes
it a copy of file descriptor 3 (which points to /tmp/test).
That means that it's not possible, as far as I can tell, unless you
can modify (A)'s behavior, for example by overloading the open
function before it starts, or save the original STDOUT filehandle,
perhaps from a BEGIN block.
Good luck!
---ScottG.