in reply to Perl Expect

Hi,

I have had a somewhat similar problem with expect, but this wasn't in Perl. Basically I had a shell program using expect to retrieve a dozen or so files from a distant server. I had no problem with relatively small files, but very large files would be truncated due to time out. The following statement in the expect part of the shell script solved the problem:

set timeout -1
I haven't used the Perl Expect module, at least not recently, but I suppose that you might be able to do something similar with it. HTH.

Replies are listed 'Best First'.
Re^2: Perl Expect
by pryrt (Abbot) on Jan 11, 2018 at 15:21 UTC
    ... I suppose you might be able to do something similar...

    I haven't used it, but Expect says, for $object->expect($timeout, @match_patterns), "If $timeout is undef Expect will wait forever for a pattern to match". That indicates your supposition is right.

    If you want to wait longer, but not forever, you can just set the $timeout accordingly... and maybe use $object->restart_timeout_upon_receive(1), which appears re-start the timer every time new data arrives (so if the command is outputting a word every 15 seconds, and can be considered dead if it goes more than 30 seconds, and the word you're looking for is the fifth word, then you could use a timeout of 30 seconds with the ->restart_timeout_upon_receive(1), and it should ... ah, enough of this "should" stuff:

    #!/usr/bin/env perl -l use warnings; use strict; use Expect; foreach my $restart (0, 1) { my $exp = Expect->new(); $exp->restart_timeout_upon_receive($restart); $exp->spawn(qw{perl -le 'foreach(@ARGV) { print $_; sleep 2; } ' w +ait until seeing the fifth word }) or die "cannot spawn: $!\n"; my @return = $exp->expect(4, 'fifth'); print "restart=$restart -> \@return = ", join ', ', map { $_ // '< +undef>' } @return; }
    Yep, that timedout on the first run, but continued through to the 'fifth' on the second run.