Garayed.com  

Go Back   Garayed.com > Perl
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-05-2006, 07:04 PM
kj
 
Posts: n/a
Default How to turn off STDOUT portably without closing it?




ExtUtils::Install::install is making some unwanted noises ("Installing
blah-blah-blah", via STDOUT) that I want to turn off, and do so in
a portable way. My first stab was simply to close STDOUT:

perl -MExtUtils::Install -e '
close STDOUT; install( { "foo" => "bar" }, 0, 0, 0 )'

....but this results in *new* unwanted noises:

Filehandle STDOUT reopened as FH only for input at /usr/lib/perl5/5.8.6/File/Copy.pm line 118.
Filehandle STDOUT reopened as FH only for input at /usr/lib/perl5/5.8.6/File/Copy.pm line 118.
Filehandle STDOUT reopened as FH only for input at /usr/lib/perl5/5.8.6/File/Copy.pm line 118.

....etc., on such line for each file copied.

I tried adding 'no warnings "io";' to the script, but that failed
to silence the warnings (why?). The only portable solution I could
find is very long-winded:

perl -MExtUtils::Install -e '
$SIG{ __WARN__ } = sub{ warn @_ unless $_[ 0 ] =~ /STDOUT reopened/ };
close STDOUT;
install( { "foo" => "bar" }, 0, 0, 0 )'

A shorter solution is

perl -MExtUtils::Install -e '
open STDOUT, ">/dev/null";
install( { "foo" => "bar" }, 0, 0, 0 )'

....but I doubt that it is portable.

A third solution would be

perl -MExtUtils::Install -e '
close STDOUT;
open STDOUT, ">", \$toss;
install( { "foo" => "bar" }, 0, 0, 0 )'

but I believe this would bomb with versions of Perl older than 5.8,
so in a sense it is not very portable either.

Is there a more succinct solution than my __WARN__ hack above?

Thanks!

kj

--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:36 PM.




LinkBacks Enabled by vBSEO 3.0.0 © 2007, Crawlability, Inc.