Re: How to local-ly close a handle?




Quoth "Ferry Bolhar" <bol@xxxxxxxxxxxxxxxxx>:
kj:

I know of ways to temporarily silence STDERR that actually work,
but none of them begins to approach the simplicity of any of the
examples above. Any suggestions?

Yes. How about:

system 'crazystuff 2>/dev/null';

Localizing STDERR with whatever has no impact on child processes,
because the parent process' STDERR (which the child inherits) still
remains open.

This is mostly just being picky :), but that would be better as

Localizing STDERR has no impact on child processes, because the parent
process' file-descriptor 2 (which the child inherits) remains open.

The point being that the confusion here is between Perl's STDERR and
perl's fd #2.

It will have an impact when you do a "print STDERR"
or somewhat similar, but it's meaningful with Perl commands only.

And although you can localize a typeglob (and its associated IO handle),
you can't localize a close! So if you close a file (as you did with "close
STDERR"), the file will remain closed, even when leaving the block!

The fd you closed will remain closed, but the Perl filehandle will
revert to pointing to its old fd, and thus will be open again. :)

Ben

--
The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching.
Assyrian stone tablet, c.2800 BC benmorrow@xxxxxxxxxxxxx
.



Relevant Pages

  • Re: Rename Perl Process
    ... Filehandles, and killing the parent. ... Do you realize that the error message from die can't make it ... Unless the close of STDERR itself failed. ... the parent process exit) and setting a new session in between ...
    (comp.lang.perl.misc)
  • Re: How to call .bat file from .NET?
    ... the parent is waiting for the child to end. ... aware that you cannot read BOTH stderr and stdout. ... Please do not send e-mail directly to this alias. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can __LINE__ be stringified?
    ... Carlos wrote: ... Only a small correction, please answer to the parent taking this into ... #define DIEfputs(msg #lines, stderr) ...
    (comp.lang.c)