I am working on a script that should run the Expect process periodically (every 5 minutes) to do some work. Below is the code that I have that starts the Expect process and does some work. The main script process does any other work at all times, for example, it can wait for user input, because of this I call this function "spawn_expect" in the thread, which continues to call it every 5 minutes, but the problem is that Expect does not work as expected.
If, however, I replace the thread with another process, that is, if I fork and let one process take care of Expect spawning and the other process do the main work of the script (for example, wait at the prompt), then Expect works fine.
My question is, is it possible to start the Pending thread? Should I resort to using a process to do this job? Thank!
sub spawn_expect {
my $expect = Expect->spawn($release_config{kinit_exec});
my $position = $expect->expect(10,
[qr/Password.*: /, sub {my $fh = shift; print $fh "password\n";}],
[timeout => sub {print "Timed out";}]);
...
}
source
share