in reply to perl expect
found some sample code i think for now this will do
my $exp = Expect->spawn("telnet localhost") or die "Cannot spawn telnet: $!\n";; my $spawn_ok; $exp->expect($timeout, [ qr'login: $', sub { $spawn_ok = 1; my $fh = shift; $fh->send("$username\n"); exp_continue; } ], [ 'Password: $', sub { my $fh = shift; print $fh "$password\n"; exp_continue; } ], [ eof => sub { if ($spawn_ok) { die "ERROR: premature EOF in login.\n"; } else { die "ERROR: could not spawn telnet.\n"; } } ], [ timeout => sub { die "No login.\n"; } ], '-re', qr'[#>:] $', #' wait for shell prompt, then exit + expect );
this is from the expect module from cpan
Thanks all who tried
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl expect
by Anonymous Monk on Dec 07, 2016 at 19:51 UTC | |
by Anonymous Monk on Dec 07, 2016 at 19:57 UTC | |
by ogg (Initiate) on Dec 07, 2016 at 20:19 UTC |