kendroid has asked for the wisdom of the Perl Monks concerning the following question:

I've got a script that performs several expect operations. I'd like to suppress what the expect code is printing but still be able to print status-like information to STDOUT.

Here's what I've got:

foreach $one (@ARGV) { open(STDOUT, ">/dev/null"); # Various expect statements that telnet to routers # listed in @ARGV and back up several files. close(STDOUT); # this is what I'd like to be printed to STDOUT. print "Done with backups for this machine."; }

(I'm using expect rather than Net::Telnet because the backup commands that are run usually require additional input before returning a prompt.)

Is there any easy way direct output to either STDOUT or /dev/null?

Replies are listed 'Best First'.
Re: Quick Redirection Question
by traveler (Parson) on Apr 27, 2001 at 23:08 UTC
    Expect.pm has:
    $expect_prog->log_file("/dev/null");
    To do that. Or you can do this:
    open SAVEOUT, ">&STDOUT"; open STDOUT, ">/dev/null"; # expect stuff here close STDOUT; open STDOUT, ">&SAVEOUT"; # normal talking to STDOUT here
    --traveler
Re: Quick Redirection Question
by suaveant (Parson) on Apr 27, 2001 at 22:38 UTC
    From what I've used of Expect, I think you should look into the options of expect... I believe it has various options for pointing the data where you want it.
                    - Ant