[TriLUG] Perl. Help. Needed.

William Sutton william at trilug.org
Wed Mar 11 15:25:19 EDT 2009


Can I suggest that, instead of opening STDOUT and printing to that, that 
you open a different file handle, say, CONFIG, and write the lines you 
want to see there, and print them as well if you want to see them on your 
screen?  Also, if you're not doing it, I suggest using

$|=1;

to turn on autoflush.


William Sutton


On Wed, 11 Mar 2009, Greg Brown wrote:

> I'm throwing my hands up in disgust.
>
> My Perl/Expect.pm script prints to STDOUT just like it should.
>
> I would like to redirect ONE PART OF THIS SCRIPT to a file from STDOUT
>
> Code snippet:
>
>        $ssh->expect(30,'(tcl)') || die "Never got the tcl prompt: $!\n";
>
>        open(STDOUT, ">./configs/$fileName") || die "can't write to
> ./configs/$fileName: $!\n";
>
>        print STDOUT "screw this script!!!!!  I"M SICK OF IT!\n";
>
>        # now send the 'show run' comamnd
>        print $ssh "exec \"show run\"\r";
>
>        print STDOUT "AGAIN!  screw this script!!!!!  I"M SICK OF IT!\n";
>
>        close (STDOUT);
>
> Now when I run the script my outfile file contains "screw this script!!!!!
> I"M SICK OF IT!"  and the "AGAIN" line - and ONLY those lines.. not the
> result of the command run by the expect module.  To make matters more screwy
> the results of 'show run' don't appear on the screen, i.e. they aren't going
> to STDOUT.  But they aren't going to the redirected file either.
>
> Why?
>
> I don't want to log the output of the entire script, just this one command.
> This should work.  If the results of my 'show run' aren't there when I
> redirect STDOUT to a file and they are there when I don't where the hell
> does it GO?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?
>
> Beer please.
> --
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG FAQ  : http://www.trilug.org/wiki/Frequently_Asked_Questions
>



More information about the TriLUG mailing list