(message resent with updated email address)
Using Expect.pm 1.15, occasionally the spawned process fails for unknown
reasons. Up to now we just exit the program, but I'd like to give it
another try. I'm not clear on what exactly to retry, though.
The code segment is currently:
my $exp = Expect->new();
$exp->raw_pty(1);
$exp->debug($debug);
$exp->log_file($nc_log) if $nc_log;
$exp->spawn("/bin/nc", $host, $port)
or die "Cannot spawn nc: $!\n";
$exp->expect(10, '-re', 'CoraScript.*$')
or log_session('NO_CORA_CMD'); # log_session() invokes die()
The process is spawned, but the subsequent expect() times out.
I could perhaps do something like the following, i.e., just abandon the
Expect object (not tested):
my $exp;
my $retries = 3;
while ( $retries ) {
$retries -= 1;
$exp = Expect->new();
$exp->raw_pty(1);
$exp->debug($debug);
$exp->log_file($nc_log) if $nc_log;
$exp->spawn("/bin/nc", $host, $port)
or die "Cannot spawn nc: $!\n";
break if $exp->expect(10, '-re', 'CoraScript.*$');
$exp->hard_close();
undef $exp;
}
log_session('NO_CORA_CMD') unless $exp;
...
But is there a cleaner or better way to approach this?
Thanks for any hints or pointers, examples, etc.
Ken
--
Ken...@al..., 907-474-6152
Water and Environmental Research Center
Institute of Northern Engineering
University of Alaska, Fairbanks
|