in reply to Suppressing console output

If I understand what you want do to correctly, whenever I want to do this, I just redirect the STDOUT filehandle to one of my own by assigning STDOUT's glob to a different one, this can be done like this...

my $mySTDOUT = (); my $oldSTDOUT = (); *oldSTDOUT = *STDOUT; *STDOUT = *mySTDOUT; my $test = 'this is a test'; print "$test\n";

After you run this, you should get NO output from that print command. So you'd want do to this in script A. Then, if you ever wanna restore STDOUT so you see it's output again, you can do this...

*STDOUT = *oldSTDOUT;

Hope that helps.

-Lunchy

Replies are listed 'Best First'.
Re^2: Suppressing console output
by Tanktalus (Canon) on Sep 16, 2005 at 19:30 UTC

    The faster/easier way to do that is:

    { local *STDOUT; open STDOUT, '>/dev/null'; # do stuff that may print out. }
    Note also that you're creating $mySTDOUT and $oldSTDOUT and not actually using them anywhere. $mySTDOUT is not the same thing as *mySTDOUT!

      I knew that $mySTDOUT isnt' the same as *mySTDOUT, but I thought I needed to create something with a 'mySTDOUT' name to keep strict from barking about *mySTDOUT, but it turns it I didn't need to. :)

      As far as not using *oldSTDOUT. You'll note I mentioned that he could use *oldSTDOUT to restore STDOUT to normal later on if he wanted to. Perhaps there's another way to do this, but if so I don't know what it is. :)

      By the way, I DO like your solution and will try to remember it for the next time I need to do this, however, it does assume one is on an OS that has a /dev/null. :)

      Cheers!

      -Lunchy