Hello monks,
I have a bit of a quandry with Expect.pm 's logging function, for some reason when I declaire a location for logging it logs all the output previous to my declaration statement in the same place, which does not make sense. It seems as though Expect is anticipating the logfile, even though I clear the accumulated text...
Here is my code regarding this precognitive problem.
#!/usr/bin/perl -w
use strict;
use Expect;
$| = 1;
my $exp = new Expect;
$exp->raw_pty(1); # treat this terminal as a raw file
$exp->log_stdout(0); # do not show terminal output to STDOUT
$exp->log_file("/dev/null"); # log all output to /dev/null
$exp->spawn("/bin/sh");
$exp->expect(2,
['such file or directory',
sub { print "ERROR: no shell\n"; die; } ],
[timeout =>
sub {
$exp->send("/usr/bin/last -5 $username\n");
$exp->log_file(undef); # should clear the log file
+location
$exp->clear_accum(); # should tell it to clear it
+s buffer
$exp->log_file(\&formatoutput); # log to function form
+atoutput
$exp->send("/bin/cat /etc/passwd\n");
}
],
);
$exp->soft_close();
sub formatoutput {
my $input = shift;
chomp($input);
$input =~ tr/\r//;
print"$input \n";
}
all feedback is apprecated.
jcpunk
by the way thanks
20030622 Edit by Corion: Changed title from 'Logging, both where it should and should not be it is'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.