From: Rui M. <rme...@te...> - 2007-05-08 18:59:33
|
First of all, thanks for the quick answer. Quoting Ken Irving: "If you can see the expected content in $stdout ..." But I can't see the expected result in $stdout. I can see the expected result (all the way to the matched prompt) being printed to my screen, = as Expect prints all the outputs by default. But I only get "Part1" of the output in $stdout (and, of course, in my file). I'm using the standard Perl save-to-file mechanism: open(DEST, '>' . $filename); flock(DEST, 2); print DEST $stdout; close DEST; This only happens when the outputs are long (and it happens ALWAYS, and = in the same spot). Do you have any idea of what this could be? Thanks. -----Original Message----- From: exp...@li... [mailto:exp...@li...] On Behalf Of = Ken Irving Sent: ter=E7a-feira, 8 de Maio de 2007 18:13 To: exp...@li... Subject: Re: [Expectperl-discuss] Output from before() gets truncated = ifit's too long On Tue, May 08, 2007 at 02:45:00PM +0100, Rui Meireles wrote: > Hi. I?m having a problem using Expect.pm >=20 > I created a script to do automated ssh to several hosts. One thing I > need to do is to enter several Cisco routers, execute the commands > terminal length 0 and show running-config and save some of the output > to a file. > > It?s all working fine, and as the commands are executed the correct > output is automatically printed in the screen (expect.pm default > option). However, when the output of the command is very long (show > running-config) the output is not correctly stored in my variable > $stdout, it?s always truncated in the same spot! >=20 > Example: (These are parts of my code) > ... > $stdout =3D $exp->before() . $exp->match() . $exp->after(); > ... >=20 > print ?###############\n?; > print ?$stdout\n?; > print ?###############\n?; > ...=20 > > What happens is that when I print $stdout the output I get is: >=20 > ############### > (1st part of output) > ############### > (2nd part of output) >=20 > And if I save $stdout to a file, only 1st part is saved (2nd part gets > truncated). > > Does anyone know why this is happening? I tried putting some sleeps > but that didn?t solve my problem. It almost seems that this works > as some kind of buffer, that only when emptied can store more data! > However, the qr/$prompt_default/ is working fine, as well as the > automatic prints to the screen! If you can see the expected content in $stdout then this probably has nothing to do with Expect.pm but rather with your perl coding. You=20 don't show how you're writing to a file. If you're open()ing and print()ing to a filehandle, Perl tries very hard to flush buffers when the script ends, even if you don't close() the filehandle, so the results you describe are not likely. My guess is that you're redirecting output to a file, so it's not even=20 a perl problem but a shell or terminal issue. Maybe you can coerce the buffer to flush by issuing a ^D or messing with the terminal settings=20 using stty, but the simplest fix is probably to do the write-to-file in the perl script and let Perl handle it. Good luck! Ken --=20 Ken Irving Water and Environmental Research Center University of Alaska, Fairbanks -------------------------------------------------------------------------= This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Expectperl-discuss mailing list Exp...@li... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |